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: 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:

Logic Errors

Some fo the techniques and tools for finding syntax errors are: 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