Chapter 5.

The module has become the standard tool for creating CGI scripts in Perl. It provides a simple interface for most of the common CGI tasks. Not only does it easily parse input parameters, but it also provides a clean interface for outputting headers and a powerful yet elegant way to output HTML code from your scripts.

We will cover most of the basics here and will revisit later to look at some of its other features when we discuss other components of CGI programming. For example, provides a simple way to read and write to browser cookies, but we will wait to review that until we get to our discussion about maintaining state, in Chapter 11.

If after reading this chapter you are interested in more information, the author of has written an entire book devoted to it: The Official Guide to Programming with by Lincoln Stein ( John Wiley & Sons).

Because offers so many methods, we’ll organize our discussion of into three parts: handling input, generating output, and handling errors. We will look at ways to generate output both with and without Here is the structure of our chapter:

  • Handling Input with

    • Information about the environment. has methods that provide information that is similar, but somewhat different from the information available in %ENV.

    • Form input. automatically parses parameters passed to you via HTML forms and provides a simple method for accessing these parameters.

    • File uploads

Get CGI Programming with Perl, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.