CMPS 335 Web Publishing
Debugging Perl Scripts
Finding and correcting errors in a program can be very time consuming
and frustrating. There are two types of errors: syntax errors and
logic errors.
Syntax Errors
The most common errors are typing-related errors. Some of the most
frequently repeated syntax errors:
- Missing semicolons
- Missing quotation marks
- Missing commas, parentheses, curly braces, brackets, etc.
- Misspelling keywords
- Bare words
Bare words are character strings without surrounding quotation marks and
that do not begin with a variable designator. Variable designators
for scalar, array, and hash variables are $, @, and %, respectively.
Some fo the techniques and tools for finding syntax errors are:
- Turning on the perl switch -c or -w
Examples: perl -c filename or perl -w filename
- Checking the shebang line: #!/usr/bin/perl
- Checking the MIME content-type statement for the script that
generates output to the browser
Logic Errors
Some fo the techniques and tools for finding syntax errors are:
- Checking the access permissions
- Using print statements to follow a variable's progress
- Using a Perl debugger
Example: perl -d filename
Examples of -w and -c switches
[jhu@cs cgi-bin]$ cat hello.cgi
#!/usr/bin/perl
$date = `date`; # date is a Unix date function
$time = time; # time is a Perl function
print "\n";
print "Hello, world.\n";
print "Today is $date\n";
print "Today is $time\n";
# End of hello.cgi
[jhu@cs cgi-bin]$ perl -c hello.cgi
hello.cgi syntax OK
[jhu@cs cgi-bin]$ perl -w hello.cgi
Hello, world.
Today is Mon Jan 28 13:46:37 CST 2002
Today is 1012247197
Return to CMPS 335 Home Page
Return to Web Site Home Page