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 . . .
In reply to Re: Want a Hashref. Getting a List in Scalar Context.
by Fletch
in thread Want a Hashref. Getting a List in Scalar Context.
by hardburn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |