hardburn has asked for the wisdom of the Perl Monks concerning the following question:
Getting right to the dirty part, here is the code:
{ my @FIELDS = qw( foo bar baz); sub set_params { { map { $_ => $_ } @FIELDS }; } } my $params = set_params; use Data::Dumper "Dumper"; print Dumper($params);
(This is a sanitized version, but I know that it demonstrates the problem. The orginal had all the CGI parameters in @FIELDS, and the value in each hash entry was the CGI param.)
I'm expecting set_params() to return a hashref. What I'm seeing is what you would get if you put a list in scalar context (the number of elements in the list--6 in the above example).
It works when set_params() is changed to:
my $params = { map { $_ => $_ } @FIELDS }; return $params;
I'm not against using the above in the code, but I am interested in why the orginal didn't work, i.e., what bit of toke.c magic did I step on this time?
$ perl -v This is perl, v5.8.2 built for i686-linux
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
|
|---|