For example using that code:
my %seen; my @distinct_elems = grep { !$seen{$_}++ } @array;
or maybe
my %seen = map { $_ => 1 } @array; my @distinct_elems = keys %seen;
The first example even gives you the number of occurence of each element.
Cheers, Flo
In reply to Re: finding the distinct elements in an array
by rafl
in thread finding the distinct elements in an array
by beginr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |