Setting & Retrieving CGI Parameters

You can set and retrieve CGI parameters easily. In these examples, the CGI field string is:

banana=yellow&squash=green&tomato=red&tomato=green

Retrieve a Single-Valued Field Named "Tomato":

Call param() with the name of the field and assign it to a scalar.


  my $banana_color = param('banana');
  # yields "yellow"

This works for both GET and POST types, including multipart/form-data.

Retrieve a Multi-Valued Field Named "Tomatoes":

Call param() with the name of the field and assign it to an array:


  my @tomatoes = param('tomato');
  # yields ('red','green')

Finding out What Parameters are Available

Call param() without any arguments. Will return the names of each of the parameters:

  my @fields = param;
  # yields ('banana','squash','tomato')

Setting Single- and Multivalued Fields:


  param(-name=>'tomato',  -value=>'red');
  param(-name=>'tomatoes',-value=>['red','green','blue']);

Parameters set in this way will be used as default values for fill-out form fields and hidden fields.


<< Previous Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Fri Oct 20 10:47:15 EDT 2000