Perl is an excellent language for writing web-based CGI scripts. In fact, the majority of the CGI scripts on the web are written in Perl. Because this is such a popular application of the language, the module CGI is included to give you a very accessible interface for writing CGI scripts. The documentation for this module is available on the web at http://perldoc.perl.org/CGI.htm. It includes many example of how to use the functions in the module for writing scripts.
Here is one example of a CGI script written in Perl with the CGI module. This script displays a form for entering a bug report. The form has a text field for entering a name, a select box for choosing an operating system, and a large text area for entering a description. Pressing the Submit button at the bottom of the form causes the data in those fields to be sent to the CGI script. The script will then display a message to indicate that the data has been received.
#!/usr/bin/perl use CGI qw/ :standard/ ; print header, start_html("Report a Bug (Duckpond Software)"), b(i("Duckpond Software")), p, b("Report a Bug"), hr; if (! param()) { print "Fill out this form and click submit.", p, start_form, table(Tr([ td([ "Name", textfield(-name=>"name", -size=>34), ]), td([ "System", popup_menu(-name= >"system", -values=>["", "UNIX Variant", "MS Windows", "Mac OS X"]), ]), td([ "Problem Description", textarea(-name=>"descript", -cols=>30, -rows=>4), ]), td([ "", submit("Submit") , ]) ])), end_form, p, "Thank you!"; } else { print br, "Thank you for your submission, ", param("name"), ".", br, "We will respond within 24 hours.", br, br, br, br; } print hr, a({-href=>"http://www.duckpond-software.com"}, "Back to Home Page"), end_html;
For more information about CGI scripting, including how to run CGI scripts, see Chapter 27.