I'm not a big fan of the unary plus solution
I agree, I was just keeping the examples in line with what the map docs were saying. Personally in this case I'd prefer map { (...) } ..., since it makes it look obvious that returning a list is intentional. OTOH I also use map {$_=>1} ... very often, but that one doesn't cause any parse trouble.
The map +{...}, ... stuff is also mentioned in the map docs, although I haven't yet seen it used in the wild - personally I'd probably write map { {...} } .... As you can tell I usually prefer map BLOCK LIST over map EXPR, LIST.
... to force an anon hash constructor use +{:to get a list of anonymous hashes each with only one entry apiece.my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs # comma at end
In reply to Re^3: strange syntax error with map (unary plus)
by haukex
in thread strange syntax error with map
by rsFalse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |