The answer is in the docs for map: perldoc -f map.
"{" starts both hash references and blocks, so "map { ..." could
be either the start of map BLOCK LIST or map EXPR, LIST. Because
perl doesn’t look ahead for the closing "}" it has to take a guess
at which its dealing with based what it finds just after the "{".
Usually it gets it right, but if it doesn’t it won’t realize
something is wrong until it gets to the "}" and encounters the
missing (or unexpected) comma. The syntax error will be reported
close to the "}" but you’ll need to change something near the "{"
such as using a unary "+" to give perl some help ...
The docs then list some examples, i prefer the syntax BrowserUk replied with, myself. You can
also use parens, FWIW:
%hash = map (("$var/$_", $_), @array);
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: Using map to assign to a hash
by jeffa
in thread Using map to assign to a hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |