Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Validating the contents of scalars using an array based list

by BrowserUk (Patriarch)
on Apr 03, 2003 at 18:04 UTC ( [id://247831]=note: print w/replies, xml ) Need Help??


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.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://247831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found