10. The CGI.pm Module
Contents:
CGI.pm is a Perl module for creating and parsing CGI forms. It is distributed with core Perl as of Perl 5.004, but you can also retrieve CGI.pm from CPAN, and you can get the very latest version at any time from ftp://ftp-hygenome.wi.mit.edu/pub/software/WWW/ . CGI is an object-oriented module. Don't let the object-oriented nature scare you off, though; CGI.pm is very easy to use, as evidenced by its overwhelming popularity among all levels of Perl programmers. To give you an idea of how easy it is to use CGI.pm, let's take a scenario in which a user fills out and submits a form containing her birthday. Without CGI.pm, the script would have to translate the URL-encoded input by hand (probably using a series of regular expressions) and assign it to a variable. For example, you might try something like this:
Regardless of whether this code actually works, you must admit
it's ugly.
With CGI.pm, the script could be written:
Even for this tiny program, you can see that CGI.pm
can alleviate many of the headaches associated with CGI
programming.
As with any Perl module, the first thing you do is call
the module with However, this is only the tip of the iceberg as far as what CGI.pm can do for you. There are three basic categories of CGI.pm methods: CGI handling, creating forms, and retrieving environment variables. (A fourth category is creating HTML tags, but we don't cover those in detail.) Table 10.1 lists most of these methods. They are also covered in more detail later in this chapter.
Each of these methods is covered later in this chapter, in alphabetical order. 10.1 HTML Tag Generation
In addition to the form-generation methods, CGI.pm also
includes a group of methods for creating HTML tags.
The names of the HTML tag methods generally
follow the HTML tag name (e.g., ![]() Copyright © 2001 O'Reilly & Associates. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|