Database Reference
In-Depth Information
Perl. The Perl CGI.pm module makes input parameters available to scripts through the
param() function. param() provides access to input submitted via either get or post ,
which simplifies your task as the script writer. You need not know which method a form
used for submitting parameters. You need not perform any decoding, either; param()
handles that as well.
To obtain a list of names of all available parameters, call param() with no arguments:
@param_names = param ();
To obtain the value of a specific parameter, pass its name to param() . In scalar context,
param() returns the parameter value if it is single-valued, the first value if it is multiple-
valued, or undef if the parameter is not available. In array context, param() returns all
the parameter's values as a list, which is empty if the parameter is not available:
$id = param ( "id" ); # return scalar value
@options = param ( "options" ); # return list
A parameter with a given name might not be available if the form field with that name
was left blank, or if there isn't any field with that name. Note too that a parameter value
may be defined but empty. For good measure, you may want to check both possibilities.
For example, to check for an age parameter and assign a default value of unknown if the
parameter is missing or empty, you can do this:
$age = param ( "age" );
$age = "unknown" if ! defined ( $age ) || $age eq "" ;
CGI.pm understands both ; and & as URL parameter separator characters.
Ruby. Ruby scripts that use the cgi module access web script parameters through the
cgi object you create for generating HTML elements. Its param method returns a hash
of parameter names and values; access this hash or get the parameter names as follows:
params = cgi . params
param_names = cgi . params . keys
The value of a particular parameter is available from the hash of parameter names and
values or from the cgi object:
id = cgi . params [ "id" ]
id = cgi [ "id" ]
The two access methods differ slightly. The params method returns each parameter
value as an array. The array contains multiple entries if the parameter has multiple
values, and is empty if the parameter is not present. The cgi object returns a single
string. If the parameter has multiple values, only the first is returned. If the parameter
is not present, the value is the empty string. For either access method, use the has_key?
method to test whether a parameter is present.
Search WWH ::




Custom Search