25.14. Perl Errors and Troubleshooting

You are bound to encounter problems when programming CGI applications in Perl. This section gives you a few examples of how to troubleshoot and fix problems you encounter.

25.14.1. Maximum Error Reporting

The first thing you should do to help troubleshoot errors is maximize the information Perl reports when it encounters an error. There are two methods to help increase the error text reported by Perl.

The first way is to use the w flag when running Perl. In your scripts, you simply add the flag to the interpreter line at the top of the script:

#!/usr/bin/perl -w

The second way to increase data reporting is to use the CGI::Carp fatalsToBrowser routine. Including this function causes Perl to attempt to output any errors to the browser window. This directive can be specified using the following line in your scripts:

use CGI::Carp qw(fatalsToBrowser);

For example, the following script will output the error in the die function, in this case ---An error occurred here---, as shown in Figure 25-1:

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
die "---An error occurred here---";
Figure 25-1. Figure 25-1

The fatalsToBrowser directive helps avoid the problem described in the next section—the dreaded Apache Internal Server Error message.

If you want to, change the default message supplied by the fatalsToBrowser routine by also importing the ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.