CS3172 > Materials > sysdocs > CGI > in Perl

J. Blustein

Web-centric Computing

[Course | Announcements | Materials | Resources]

System Documentation

Help Fixing CGI problems in Perl

  1. When programming with Perl 5 you should use the built-in help to detect errors before they become serious problems, and to explain them when they do occur:

    1. include the -w switch when invoking perl, for example:
      #!/opt/bin/perl -Tw
      as the very first line of your program.
      • (The -T switch is discussed below in the section specifically about CGI programming.)
    2. include the strict pragma at the start of the program (before any other code):
      use strict;
    3. ask for verbose error messages to help you when you debug:
      use diagnostics;
  2. when programming CGI programs with Perl 5 you should take these additional steps also:

    1. include the -T switch before any other switches when invoking perl, for example:
      #!/opt/bin/perl -Tw
      as the very first line of your program.
      • The -T switch turns on taint checking which is needed for form processing. (The -w switch is discussed above, in the section about programming in Perl in general.)
    2. flush the output stream after every output statement by putting this pragma at the start of your program:
      $| = 1;
      or
      use English;
      $OUTPUT_AUTOFLUSH = 1;
  3. if you use the CGI.pm module (which I recommend) then

    1. tell it to send error messages to the WWW browser by putting the following line at the beginning of your program:
      use CGI qw(:standard :Carp -debug);
      and
    2. also tell it to send error messages that include details about where the problem really happened by putting the following line at the beginning of your program:
      use CGI::Carp 'fatalsToBrowser';
    3. read the CGI.pm documentation webpage at the author's website, and other information at the the main perl documentation website (perldoc.perl.org).

See Also

I also recommend Tom Christiansen's list of common CGI mistakes made by Perl programmers.

See the the advice2.pl script, in the examples subsection, as an example of a simple working CGI program.


http://www.cs.dal.ca/~jamie/course/CS/3172/Materials/Docs/cgi-advice/perl-cgi-debug.html
Version:
27 June 2003
Author:
J. Blustein <jamie@cs.dal.ca>

Valid XHTML 1.0!
Creative Commons License