Index   -   Next  >


What is CGI.pm?


- CGI.pm : A Perl5 CGI Library -

CGI.pm: a Perl module written by Lincoln Stein, a bioinformatics researcher at Cold Spring Harbor Laboratory, NY.

CGI.pm uses objects to create HTML forms on the fly and to parse their contents. It provides a simple API for parsing and interpreting query strings passed to CGI scripts with a rich set of functions for creating forms. Instead of remembering the syntax for HTML, you just make a series of Perl function calls.

As a student familiar with HTML and new to Perl, the advantage of this last point may be somewhat lost. A Perl programmer with little knowlege of HTML would have a different perspective.

Read all about it from the man himself


Simple Form Example Using CGI.pm

Things to note about form.pl

#!/usr/local/bin/perl

# form.pl - k.mcmanus@gre.ac.uk 20001026

# Form example CGI program:
#     accepts data from a form
#     returns the form data and ENV data as XHTML to usesr

use CGI qw(:standard);

print header;
print
   start_html(-title=>'Example Form Data', -BGCOLOR=>'#ffdddd'),
   h2('The following data is available through CGI:');
foreach $name (param) {
   print "\n       ", $name, "   ";
   foreach $val (param($name)) {
      print "       ", $val
   }
   print br;
}
print hr, "\n";
@keylist = keys(%ENV);
foreach $key (@keylist) {
   print "\n       ", $key, "   ", $ENV{$key},br;

}
print end_html;

Index   -   Next  >

best viewed using Mozilla browsers
© k.mcmanus 2004
Valid XHTML 1.0! . Valid CSS . WCAG priority 3 approved