Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: (Ovid) Re: Best way to parse CGI params

by KILNA (Acolyte)
on Feb 15, 2002 at 23:07 UTC ( [id://145785]=note: print w/replies, xml ) Need Help??


in reply to (Ovid) Re: Best way to parse CGI params
in thread Best way to parse CGI params

Actually you have just inspired my new one-line drop-in replacement for $cgi->Vars()...
$params = $cgi->Vars();
... becomes ...
$params = { map { $_ => ($cgi->param($_))[0] } $cgi->param };
... or if you want a straight hash instead of the hashref that Vars() gives you, you can ...
%params = map { $_ => ($cgi->param($_))[0] } $cgi->param;
This way seems DWIMmer since it returns what I expect most people *think* $cgi->Vars() does, which is a hash with a single scalar as the value, which ignores multiple instances of cgi params. I can't think of any time where I've actually needed multiple instances of the same name CGI parameter back (Then again, I avoid multi-select boxes ;). If I do need multiple values, you can still get at them via $cgi->param('foo'), or Ovid's method. Since mine doesn't require dereferencing the arrayref, it may be a little more convenient for newbies.

-- KILNA - pop music for cyborgs - http://www.kilna.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found