19.5. Less Typing

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, start_html(string) returns string as an HTML title, h1(string) returns string as a first-level HTML heading, and p(string) returns 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:

:cgi

Import all argument-handling methods, such as param().

:form

Import all fill-out form generating methods, such as textfield().

:html2

Import all methods that generate HTML 2.0 standard elements.

:html3

Import all methods that generate HTML 3.0 elements (such as <table>, <super>, and <sub>).

:netscape

Import all methods that generate Netscape-specific HTML extensions.

:shortcuts

Import all HTML-generating shortcuts (that is, "html2" + "html3" + "netscape").

:standard

Import "standard" features: "html2", "form", and "cgi".

:all

Import all the available methods. For the full list, see the CGI.pm module, where the variable ...

Get Learning Perl, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.