Yes, the map is broken, but only because there is no taking into account multiple values for a name. If that is fixed, I prefer it to Vars() for two reasons. First, you can use a proper data structure instead of having to split on NULs. Second, why introduce NULs when we know that they can be used to create security holes? One way to fix the map is this:
my %param = map { $_ => [$cgi->param($_)] } $cgi->param();
That works, but then all values are array refs and many object. A cleaner method allows most values to simply be values and only create array refs when you have multiple values:
#!/usr/bin/perl -wT use strict; use CGI qw/:standard/; my %params = map { $_ => get_data( $_ ) } param; sub get_data { my $name = shift; my @values = param( $name ); return @values > 1 ? \@values : $values[0]; }
Of course, some might argue about inconsistent mixing of array refs and regular scalars, but I still think it's cleaner.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re(3): Creating vars from URI and printing %ENV
by Ovid
in thread Creating vars from URI and printing %ENV
by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |