Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- validating a group of variables
- Robert Valcourt
July 6, 2007, 11:13 pm
rate this thread
July 6, 2007, 11:53 pm
Re: validating a group of variables
use CGI ':cgi-lib';
$params = Vars;
Many people want to fetch the entire parameter list as a hash in which
the keys are the names of the CGI parameters, and the values are the
parameters' values. The Vars() method does this. Called in a scalar
context, it returns the parameter list as a tied hash reference.
Changing a key changes the value of the parameter in the underlying
CGI parameter list. Called in a list context, it returns the parameter
list as an ordinary hash. This allows you to read the contents of the
parameter list, but not to change it.
When using this, the thing you must watch out for are multivalued CGI
parameters. Because a hash cannot distinguish between scalar and list
context, multivalued parameters will be returned as a packed string,
separated by the "" (null) character. You must split this packed
string in order to get at the individual values. This is the
convention introduced long ago by Steve Brenner in his cgi-lib.pl
module for Perl version 4.
If you wish to use Vars() as a function, import the :cgi-lib set of
function calls (also see the section on CGI-LIB compatibility).
July 6, 2007, 11:55 pm