About Linux FAQ

Browse More FAQs:

Display or view the perl cgi errors in a web browser

Posted by Vivek on Wednesday June 13, 07 @7:16 pm

Q. I’m currently learning Perl cgi programming and coded a small web site in a Perl. Usually errors are logged in a log file. How can I view the perl cgi errors in a we browser like firefox?

A. CGI scripts have a nasty habit of leaving warning messages in the error logs that are neither time stamped nor fully identified. Tracking down the script that caused the error is a pain.

You need to install and use CGI::Carp module.

With this module the standard warn(), die (), croak(), confess() and carp() calls will automatically be replaced with functions that write out nicely time-stamped messages to the HTTP server error log.

You can also log message to a browser. Now add following two lines before sending any headers to a browser:

use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 

With above lines it is possible to make non-fatal errors appear as HTML comments embedded in the output of your program. To enable this feature, export the new "warningsToBrowser" subroutine. Since sending warnings to the browser before the HTTP headers have been sent would cause an error, any warnings are stored in an internal buffer until you call the warningsToBrowser() subroutine with a true argument.

See official CGI::Carp man page for more information.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Discussion on This FAQ

  1. Luke Says:

    Hi Vivek,
    Just pointing out a typo at the end of your post - isn’t it called CGI::Carp, and not CGI::Crap? You seem to have mispelled your link to the man page(although the link still works).

  2. vivek Says:

    Luke,

    Thanks for the heads up! FAQ has been updated.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

~ Last updated on: June 17, 2007

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.