Passing Information to Your CGI Program

When a CGI program is run as the result of a form submission, the field names and values passed in from the form—called parameters—need to be processed by the CGI program. This is done with the param function.

Without any arguments, the param function returns the names of the fields being passed into the CGI program. If the CGI program were accepting the form in Listing 18.1, the param function would return body, sex, name, and submit.

With an argument, param returns the value of that parameter. For example, param('sex') would return the value of the radio buttons—either male or female—depending on which was selected.

Listing 18.2 contains a short CGI program to print these parameters.

Listing 18.2 CGI ...

Get Sams Teach Yourself Perl in 24 Hours 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.