On 5/18/2004 10:46 PM, James Edward Gray II wrote:
On May 18, 2004, at 9:14 PM, Jason Dusek wrote:
Hi,
Is there an easy way to get all the unique elements of an array? i.e.
is there some module or function that does that sort of thing?
There are excellent modules to handle this, but it's also pretty simple
to roll your own in most cases:
sub unique { # see title of this message for usage
my @all = @_;
my %seen;
$seen{$_}++ foreach @all;
return keys %seen;
}
or it can be made uglier:
sub uniq { return keys %{{ map { $_, 1 } @_ }} }
Isn't this in the faq? `perldoc -q faq`
Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>