Examples in Perl

Debugging Perl

If you buy space from a web hosting service, you usually don't have access to the command prompt.
This makes debugging your perl script very difficult as you can no longer see the error messages printed.
Well, the solution is to use "perl -c <perl script>" to check the syntax of the script.
But this still sends the errors to standard error and not standard output.
So, we will additionally need to redirect STDERR to STDOUT.


open (STDERR, ">&STDOUT");

`perl -c $perl_script`;

Accept $perl_script from a HTML form to make it general and avoid changing the script for each new script you want to check.
However, be warned that if it is a form, there's no stopping anyone from entering the script name as "name.pl; rm *", which makes the command "perl -c name.pl; rm *".
Certainly not what you expected :)
Hint: You can use .htaccess files to password protect pages.

Back to Table of Contents