in reply to Strange compiler behavior with map?
The compiler has to decide whether "{" is the start of a block or the start of a hash constructor.
The standard way to disambiguate would be:
my %unique = map {; "$_" => 1 } @objects;
But this would work:
my %unique = map { $_ => 1 } @objects;
By the way, if you want to preserve the original order, you can use:
my %seen; my @unique = grep !$seen{$_}++, @objects; print @unique;
Also, it won't convert your objects into strings.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange compiler behavior with map?
by dwalin (Monk) on Sep 05, 2011 at 09:26 UTC | |
by Anonymous Monk on Sep 05, 2011 at 09:37 UTC | |
by ikegami (Patriarch) on Sep 06, 2011 at 00:51 UTC |