10.6 Debugging (Perl in a Nutshell)

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 10.5 Using JavaScript FeaturesChapter 10
The CGI.pm Module
Next: 10.7 CGI.pm Reference
 

10.6 Debugging

A complication of writing CGI scripts is that when debugging the script, you have to wrestle with the web server environment. CGI.pm provides support for debugging the script on the command line.

If you run the script on the command line without arguments, you will be placed into an "offline" mode, in which name-value pairs can be entered one-by-one. When you press CTRL-D, the script runs. For example:

% birthday
(offline mode: enter name=value pairs on standard input)
birthday=6/4/65
^D
Content-type: text/html

<P>Your birthday is 6/4/65.</P>
You can also supply the name/value parameters directly on the command line. For example:
% test birthday=6/4/65
Content-type: text/html

<P>Your birthday is 6/4/65.</P>
Multiple values can be separated by spaces (as separate arguments on the command line) or by ampersands (as in URL-encoded syntax). In fact, you can use URL-encoded syntax on the command line. This makes it easy to supply raw CGI input to the script for testing purposes. Just remember to protect the ampersand from the shell.
% test 'birthday=6%2f4%2f65&name=Fred%20Flintstone'
Content-type: text/html

<P>Fred Flintstone, your birthday is 6/4/65.</P>


Previous: 10.5 Using JavaScript FeaturesPerl in a NutshellNext: 10.7 CGI.pm Reference
10.5 Using JavaScript FeaturesBook Index10.7 CGI.pm Reference

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.