First some solutions, then I'll explain.
map(($_ => 2*$_), @list) map +($_ => 2*$_), @list map { $_ => 2*$_ } @list
In general terms, what's an EXPR and what's not (and why can't $_ => 2*$_ be one)?
You gotta keep in mind the entire list of arguments is also an expression (a list operator), so the expression is bounded by a comma. "=>" is a fancy form of the comma operator.
So why you have is basically a precedence issue. And when you have a precedence issue, you use parens.
map(($_ => 2*$_), @list)
map is often used without parens, but that's a problem here since
map ($_ => 2*$_), @list # XXX
means
map(($_ => 2*$_), ()), @list # XXX
The usual trick is to use the unary + operator.
map +($_ => 2*$_), @list
Omitting parens around function in Perl is frought with peril.
In reply to Re: map EXPR - what's an EXPR?
by ikegami
in thread map EXPR - what's an EXPR?
by missingthepoint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |