in reply to Want a Hashref. Getting a List in Scalar Context.
It's seeing the braces as a BLOCK. If you prefix it with a + it'll force it to be interpreted as an EXPR and hence generate a hashref.
{ my @FIELDS = qw( foo bar baz); sub set_params { +{ map { $_ => $_ } @FIELDS }; } } my $params = set_params; use Data::Dumper "Dumper"; print Dumper($params);
There's another semi-common case where this happens, but I can't recall it off hand . . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Want a Hashref. Getting a List in Scalar Context.
by artist (Parson) on May 04, 2004 at 21:18 UTC |