While using map certainly works, using map in a void context like you do is inefficient. Map returns an array for you regardless of whether you use it or not. As a result using map as a surrogate for loop is bad practice. In golf you use it because it is 2 chars shorter than a for loop. That is about the only (valid) reason to use it in a void context :-) All you actually want is:
$help{$_}++ for @a
This is far more efficient, it is also shorter for what it's worth. Thanks to chipmunk for straigtening me out on this some months ago.
my @a= (1,2,3,4,5,6,6,5,4,3,2,1); my %help; my @wasted_array = map { $help{$_}=1 } @a; @a = keys %help; print @wasted_array, "\n", @a;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Re: Removing Duplicate Array Elements!!!
by tachyon
in thread Removing Duplicate Array Elements!!!
by dnickel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |