That's still a lot of typing. It turns out that CGI.pm includes a whole slew of convenience functions for simplifying this. Each of these routines returns a string for you to output. For example,
header() returns a string containing the
Content-type line with a following blank line,
string as an HTML title,
string as a first-level HTML heading, and
string as a new HTML paragraph.
We could list all these functions in the import list given with
use, but that will eventually grow too unwieldy. However, CGI.pm, like many modules, provides you with import tags - labels that stand for groups of functions to import. You simply place the desired tags (each of which begins with a colon) at the beginning of your import list. The tags available with CGI.pm include these:
Import all argument-handling methods, such as
Import all fill-out form generating methods, such as
Import all methods that generate HTML 2.0 standard elements.
Import all methods that generate HTML 3.0 elements (such as
Import all methods that generate Netscape-specific HTML extensions.
Import all HTML-generating shortcuts (that is, "html2" + "html3" + "netscape").
Import "standard" features: "html2", "form", and "cgi".
Import all the available methods. For the full list, see the CGI.pm module, where the variable
%TAGS is defined.
Here's our program using all the shortcuts CGI.pm provides:
#!/usr/bin/perl -w # cgi-bin/ice_cream: program to answer ice cream # favorite flavor form (version 2) use CGI qw(:standard); print header(), start_html("Hello World"), h1("Greetings, Terrans!"); my $favorite = param("flavor"); print p("Your favorite flavor is $favorite."); print end_html();