(Ovid) Re: Best way to parse CGI paramsby Ovid (Cardinal)
|on Feb 15, 2002 at 16:07 UTC||Need Help??|
A note regarding CGI::Vars(): I never use it. It was created to ease the transition from the Perl4 cgi-lib.pl and the Perl5 CGI.pm. As a result, it uses the NUL byte (ASCII zero) to delimit multiple values. Since the NUL byte hack is so dangerous, I prefer not not to deliberately introduce them.
One quick and easy way of getting all params is the following:
Some might prefer the following:
With the last snippet, if you only have one param value, the hash value is a scalar value. If you have multiple param values, the hash value is a reference to an anonymous array.
I used to think the last method was better, but as tilly alluded to above, and as I have seen before, most code that uses the ref function has problems. Most of the time, such code can be rethought to more naturally model the problem without having to insert a lot of extra logic to see what type of reference you are getting at any given time. Of course, that comes with the caveat that the only hard and fast rule is that there are no hard and fast rules.
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.