in reply to Re: Deciding unique elements of an array
in thread Deciding unique elements of an array
You have a strange definition of unique :) ... your code removes any entries which don't occur exactly once, try for example this:
my @array = qw/one one two/; # your algorithm print @uniques; # prints 'two' # and I would expect 'onetwo'
So changing that and putting it a bit shorter:
my %count = (); my @uniques = grep {! $count{$_}++} @array;
... and btw this should be in the FAQs somewhere.
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(3): Deciding unique elements of an array
by FoxtrotUniform (Prior) on Nov 15, 2001 at 22:03 UTC |