in reply to Validating the contents of scalars using an array based list
Instead of fetching your form values individually, look at the CGI::Vars() method for retrieving a hash containing them.
If you then hold the values which you are comparing against in another hash, the comparison becomes a simple loop.
If you are looking for exact equality between the two lists, you can even use grep in the conditional.
my %checks = (var1=>'foo', var2='bar', var3=>'qux' ); my %params = q->Vars; complain() unless keys %checks == grep{ $param{$_} eq $checks{$_} }keys %checks;
This relies on both grep and keys returning numeric values in a scalar context to determine if all the values in values in %checks had equivalent keys with the same value in %params.
|
|---|