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

    You have a strange definition of unique :) ... your code removes any entries which don't occur exactly once

    Oh, I don't know, I like my definition. :-) I read (misread?) the question as "pick out the elements that occur just once" rather than "make a copy of the list with duplicate elements removed".

    ... and btw this should be in the FAQs somewhere.

    I believe it is, as mentioned in an earlier response.

    --
    :wq