I have noticed a lot of AM nodes asking about CGI errors, usually "here's my script. When I run it I get an Internal Server Error! Whats wrong with it?"
Usually the answer is "Go check your web server logs!! (grr)". Nothing wrong with that, for most cases it is where the problem will be found and solved. I'm sure there are already a hundred faqs that point to the same answer.
But for those testing scripts on some "free" web servers where you generally cant get at the logs, this is a bit difficult. Especially if the person doesnt have a computer of their own to test it on. (it might sound far fetched but in some courses it happens).
I have come up with a quick (very-simple, no doubt its been done before) solution for debugging cgi scripts. Its simply a caller script that sends errors/warnings out to stdout (the browser). This simply sets up STDERR to print to STDOUT, checks for CGI.pm checks that your script exists and then calls the script that you are debugging. Errors / Warnings will be output as they occur.
#!/usr/bin/perl -w
use strict;
my $scr = "script.pl"; #put name of script here
print "Content-Type: text/html;\n\n";
*STDERR = *STDOUT;
eval {require CGI};
print $@ if $@;
if (-f $scr)
{
do "$scr";
print $@ if $@;
}
else
{
print "$scr not found";
}
To use:
Save as "debug.pl"
Change the $scr assignment to the script to be debugged
Call debug.pl from the web browser
Note: The content type will be printed by the caller script, and as such when it is printed by the script being debugged it will appear in the browser window (this should be ignored). This is to enable any initial compiler/file errors to be printed.