Using for parsing the query string

In order for your Perl program to be able to use the subroutines included in the package, write the following command somewhere near the top of your program:
use CGI qw(:standard);

The param function

Given a name as an argument, the param function returns its corresponding value from the key-value pairs in the query string.


URL: http://.../program_name?name1=value1&name2=value2&name3=value3

$a = param ("name1"); # $a is now "value1"
$b = param ("name2"); # $b is now "value2"
$c = param ("name3"); # $c is now "value3"

If the param function is called without arguments, it returns an array of all the names that appeared in the query string.

Example, for the above URL:

@names = param(); # @names is now ("name1", "name2", "name3")

Find out yourself: how can you retrieve a list of the values in the query string?

Table of Contents.
Previous | Next.