Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Tips for Convenient CGI Scripting

By Eugene Logvinov
2005-04-14


CGI::LogCarp usage and shortcomings

When you use the diagnostics and the CGI::Carp modules together, you come up with a few interesting results. CGI::Carp sets the $::SIG{__WARN__} and $::SIG{__DIE__} signal handlers in an approximate manner, while the diagnostics module expands the installed signal handler. This is why the order that the modules are included in the use statement is important. Moreover, the module does not allow presentation of the whole STDERR on the browser screen, and as a result, only a snippet of the module's code is used.

Additional error data displayed by the diagnostics module are not always easily readable, because of repetitive (and annoying) error messages. This is especially true with the -verbose flag, which should only be used when you first start out.

Another imperfection in our example is the relatively long compilation time, which can be avoided by copying code fragments to another module. It's better to use tied file handles to write STDERR directly to a scalar value, and to subsequently display errors in the browser, than to write STDERR to a file. Unfortunately, this is currently impossible due to a Perl bug.

Jan Pazdziora, the author of the Tie::STDERR module, admits that "the Tie::STDERR catches the compile time errors, but it doesn't get the reason, only the fact that there was an error. I do not know how to fix this." So the only current solution is to redirect STDERR to the file.

After completing the script design and test stages, it is a good idea to skip the debug stage and upload a snippet of code to the server first. Perl Diver (a simple Perl script) could be used to determine some server features (installed modules, the location of sendmail, environment variables, etc.). You can also take a look at the script's detailed description.

Tutorial Pages:
» Tips for Convenient CGI Scripting
» The CGI module
» Displaying script errors in the browser
» CGI::LogCarp usage and shortcomings
» Standard modules of CGI::* type
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» Random subroutines in Perl
» Log Script Use
» Creating Perl Modules for Web Sites
» Bit Vector, Using Perl Vec
» Build a Perl/CGI Voting System
» Perl Range Operator

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources