Contents
15. Testing Perl Programs
Use the compiler -w
switch to warn about identifiers that are
referenced only once, uninitialized scalars, redefined subroutines, undefined
file handles, probable confusion of "==" and "eq", and other things. This can be
coded in the magic cookie first line:
#!/usr/local/bin/perl -w
As you write your program, put in print
statements to display
variables as you proceed. Comment "#" them out when you feel you don't need to
see their output.
CGI scripts require some special attention in testing.
MU's "showme" and "SGI" Web servers (www.missouri.edu and
www.cclabs.missouri.edu) use the Apache "sucgi" facility. This causes CGI
programs stored under your directory ~/www/ with file name ending ".cgi" to
execute as your own ID. On some other Web server the script does not execute
under your login ID! It executes under the ID of the Web server, typically as
user "nobody".
Thus a script that works at the command line may fail under the Web server
because:
The path for executables or Perl library might be inappropriate. Print
$ENV{'PATH'} and @INC to see if there's a difference. Fix it with Perl
statements like: $ENV{'PATH'} .= ':~myid/bin:~myid/cgibin';
push @INC,'~myid/lib/perl';
File permissions give your ID access don't give the Web server appropriate
access.