in reply to map syntax bug-a-boo?
If the opening curly brace is followed by a string and a comma (, or =>), perl guesses it's an anonymous hash. Anything else, and perl guesses it's a block. This heuristic works most of the time, but in some cases perl guesses wrong:
However, there's not much urgency to fix this problem, because it's so easy to avoid:# a block returning a list of two elements, # but perl thinks it's an anonymous hash %hash = map { "$_", 2 } @l; # an anonymous hash, but perl thinks it's a block @hash_refs = map { $_, 2 }, @l;
# force parsing as a block %hash = map { +"$_", 2 } @l; %hash = map { ; "$_", 2 } @l; %hash = map { ( "$_", 2) } @l; # force parsing as an anonymous hash @hash_refs = map +{ $_, 2 }, @l;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: map syntax bug-a-boo?
by shotgunefx (Parson) on Nov 30, 2001 at 17:38 UTC | |
by dmmiller2k (Chaplain) on Nov 30, 2001 at 19:21 UTC | |
by chipmunk (Parson) on Dec 01, 2001 at 09:39 UTC |