Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If you're trying to debug a CGI script, CGI::Carp could be your best friend. It makes getting error messages from CGI scripts with a browser practically as easy as from other scripts at the command line.

My favorite feature is also the easiest to use. Import the special symbol fatalsToBrowser like this:         use CGI::Carp qw(fatalsToBrowser);

Now, if have a syntax error in your script that would abort execution due to compilation errors, say, instead of getting a server error from your HTTP server that isn't very informative, you get a message telling you that there are compilation errors. If I used perl -c more often, I probably wouldn't be so attached to this feature.

On the downside, information about what line the error is at doesn't show up in your browser. It would be nice if it did. However, you can retrieve that information from your HTTP server's error log.

Once you get past syntax errors, anything that you want to die() or croak() about will go to the browser, too, if you've imported fatalsToBrowser. If you want warnings to go to the browser as well, import the carpout() function and use it to redirect STDERR.

You can also use carpout() to redirect STDERR to your own log file, instead of the server's error log. Here's the example from perldoc CGI::Carp:

BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or die("Unable to open mycgi-log: $!\n"); carpout(LOG); }

These conveniences make CGI programming a lot easier, and they make CGI::Carp one of my favorite modules.


In reply to CGI::Carp by redcloud

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found