Perl
  Home arrow Perl arrow Page 9 - Carping About DBI
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PERL

Carping About DBI
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2001-05-02


    Table of Contents:
  • Carping About DBI
  • Dissecting The DBI
  • Animal Antics
  • Do()ing More
  • When Things Go Wrong
  • Speed Demon
  • Dummy Data
  • Croak!
  • Whining Some More
  • Final Thoughts

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Carping About DBI - Whining Some More
    ( Page 9 of 10 )

    The Carp module also comes with a bunch of additional features designed specifically for use in Perl CGI scripts. These features make it easier to track errors thrown up by your CGI scripts, and to log these errors appropriately.

    When running as a CGI script, your error output is automatically redirected to the HTTP server error log. Unfortunately, the output is not time-stamped, making it difficult to figure out when the error occurred. To get time-stamped error and warning messages, simply replace the line

    use Carp;
    


    with

    use CGI::Carp;
    


    The rest of your code remains the same.

    Another nifty little feature here is the ability to echo error messages (though not warnings) to the client browser. Simply import the fatalsToBrowser() subroutine and this will be done for you automagically. Change the line

    use CGI::Carp;
    


    to

    use CGI::Carp qw(fatalsToBrowser);
    


    Now, not only will errors be recorded in the log, but they will also be displayed to the user. This may or may not be something you want (do you really want the world to see the error messages your shoddy little script vomits out?), which is why it has to be turned on manually by importing fatalsToBrowser().

    Finally, the carpout() function allows you to redirect error messages to a file of your choosing, rather than sending them to the standard error log. This can be a great help while debugging, since you won't have to wade through miles of log file messages in order to find the hairballs you script coughed up.

    Here's an example:

    BEGIN {
    use CGI::Carp qw(carpout);
    open (CARPLOG, ">>/usr/home/luser/my-script.log") or die ("Can't open log
    file!");
    carpout(CARPLOG);
    }
    


    As you can see, carpout() has to be specially imported in before it can be used. carpout() needs just one parameter, the file handle of the user-defined error log.

    Keep in mind that carpout() degrades performance and should not be used in an actual production script. Use it only as a tool for debugging your script, or as an excuse to explain why it's so slow.

    This article copyright Melonfire 2001. All rights reserved.

     
     
    >>> More Perl Articles          >>> More By Vikram Vaswani, (c) Melonfire
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek