next up previous contents
Next: A Minimal Form Response Up: CGI Script Input: Accepting Previous:

The module

Details of this module may be found at

This perl 5 library uses objects to create Web fill-out forms on the fly and to parse their contents. It provides a simple interface for parsing and interpreting query strings passed to CGI scripts. However, it also offers a rich set of functions for creating fill-out forms. Instead of remembering the syntax for HTML form elements, you just make a series of perl function calls. An important fringe benefit of this is that the value of the previous query is used to initialize the form, so that the state of the form is preserved from invocation to invocation.

Everything is done through a ``CGI'' object. When you create one of these objects it examines the environment for a query string, parses it, and stores the results. You can then ask the CGI object to return or modify the query values. CGI objects handle POST and GET methods correctly, and correctly distinguish between scripts called from <ISINDEX> documents and form-based documents. In fact you can debug your script from the command line without worrying about setting up environment variables.

A script to create a fill-out ( form that remembers its state each time it's invoked is very easy to write with


use CGI qw(:standard);

print header;
print start_html('A Simple Example'),
    h1('A Simple Example'),
    "What's your name? ",textfield('name'),
    "What's the combination?",
    "What's your favorite color? ",

if (param()) {
        "Your name is",em(param('name')),
        "The keywords are: ",em(join(", ",param('words'))),
        "Your favorite color is ",em(param('color')),
print end_html;

However for the ramainder of this course we will not use as we will concentrate on CGI aspects that would get clouded with the employemnt of the large module.

We keep things simple for easier understanding.


Real CGI Perl programmer always use this module. If this is your game you should take time out to leran and harness the routines available here as they will save you mush effort in the future.

Using is not advised with objetc oriented perl 5. Infact if you use the strict pragma or evenet the -w option you will get warning errors for good code as contains some poor perl.

But it has a good purpose thats saves us some effort when learning some simple Perl CGI.

Lets now look at a minimal Perl program to read a CGI script.

next up previous contents
Next: A Minimal Form Response Up: CGI Script Input: Accepting Previous: