Contents / Previous / Next


CGI.pm and mod_perl

CGI.pm offers a rich set of functions for creating HTML forms and a simple interface for parsing and interpreting query strings passed to CGI scripts.

mod_perl isa persistent Perl interpreter embedded in a (Apache) web server.


cgi-lib

The cgi-lib.pl library has become the de facto standard library for creating Common Gateway Interface (CGI) scripts in the Perl language.
-----------------------
The following Material is taken from the original page by Steven E. Brenner: cgi-lib.berkeley.edu/index.html#doc
Please consult the original if still available.
-----------------------

Example:


This is the HTML source for the form:

<form method="post" action="simple-form.cgi"></form> <h2> Pop Quiz: </h2> What is thy name: <input name="name"><p> What is thy quest: <input name="quest"></p><p> What is thy favorite color: <select name="color"><option selected="selected">chartreuse </option><option>azure </option><option>puce </option><option>cornflower </option><option>olive draub </option><option>gunmetal </option><option>indigo2 </option><option>blanched almond </option><option>flesh </option><option>ochre </option><option>opal </option><option>amber </option><option>mustard </option></select> </p><p> What is the weight of a swallow: <input type="radio" name="swallow" value="african" checked="checked"> African Swallow or <input type="radio" name="swallow" value="continental"> Continental Swallow </p><p> What do you have to say for yourself <textarea name="text" rows="5" cols="60"></textarea> </p><p> Press <input type="submit" value="here"> to submit your query.


This is the Perl source for the file "simple-form.cgi" hat processes the form:

#!/usr/local/bin/perl # $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.4 1996/03/29 22:07:56 brenner Exp $ # Copyright (C) 1994 Steven E. Brenner # This is a small demonstration script to demonstrate the use of # the cgi-lib.pl library require "cgi-lib.pl"; MAIN: { # Read in all the variables set by the form &ReadParse(*input); # Print the header print &PrintHeader; print &HtmlTop ("cgi-lib.pl demo form output"); # Do some processing, and print some output ($text = $input{'text'}) =~ s/\n/\n<BR>/g; # add <BR>'s after carriage returns # to multline input, since HTML does not # preserve line breaks print <<ENDOFTEXT; You, $input{'name'}, whose favorite color is $input{'color'} are on a quest which is $input{'quest'}, and are looking for the weight of an $input{'swallow'} swallow. And this is what you have to say for yourself:<P> $text<P> ENDOFTEXT # If you want, just print out a list of all of the variables. print "<HR>And here is a list of the variables you entered...<P>"; print &PrintVariables(*input); # Close the document cleanly. print &HtmlBot; }

The simple-form.html and simple-form.cgi have been combined into a single script.