How do I debug a Perl script?
If your Perl script doesn't work, the first thing to do is use our CGI Script Checker, which will verify that the script has the correct path and that it was uploaded in text mode.
If the Script Checker says the file is okay, you should examine the Web server error logs:
- Login to the “My Account” control panel (having trouble?)
- Click Statistics and Logs
- Click the link to view the error log details.
In most cases, this will show the Perl errors.
Seeing Perl errors in the browser
If your script compiles, but dies before finishing and you want to see the error in your browser instead of the error logs, you can add the following extra text as the second line of your Perl script, right below the "
use CGI::Carp qw(fatalsToBrowser);
This will display the Perl errors in your Web browser when you run the script. (You should remove this line once you've solved the problem, as it can potentially reveal parts of your script's source code to your visitors.)
This only works for "runtime" errors, though. It won't show errors in the browser if the Perl script actually fails to compile.
Seeing Perl warnings in the browser
If you want to do a similar thing with Perl warnings as well, use this instead:
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); # ... some code that prints the HTTP header ... warningsToBrowser(1);
That will include any Perl warnings in the Web page as embedded HTML comments. Just be careful that you don't call
warningsToBrowser(1); until after you print the HTTP header (see the CGI::Carp documentation for details about this).
Copyright © 2000-2023 Tiger Technologies LLC