Let's say I have a list of @objects interspersed with scalar values, and I want to get a list of unique stringified values of all @objects. Each $object has "" operator overloaded so naturally I try to do the intuitive thing:
my @objects = (); my %unique = map { "$_" => 1 } @objects; print sort keys %unique;
Contrary to my expectation, the construct above produces compiler error:
Not enough arguments for map at test.pl line 2, near "} @objects" syntax error at test.pl line 2, near "} @objects" Execution of test.pl aborted due to compilation errors.
Changing the offending line to...
my %unique = map { ''.$_ => 1 } @objects;
...resolves the error. But still there's something I can't understand about it. Why the more natural-looking construct is erroneous, while less intuitive works as expected? Is that another compiler quirk I just have to live with?
Regards,
Alex.
In reply to Strange compiler behavior with map? by dwalin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |