in reply to Re: Removing Duplicates in an array?
in thread Removing Duplicates in an array?

Looks a bit over-engineered to me :)

my %unique; @unique{@list} = @list; @list = keys %unique;
--
<http://www.dave.org.uk>

Perl Training in the UK <http://www.iterative-software.com>

Replies are listed 'Best First'.
Re: Re: Re: Removing Duplicates in an array?
by mr.nick (Chaplain) on Jun 26, 2001 at 17:55 UTC
    TIMTOWTDI: How about one that preserves the original order?
    @a=qw( one two three for five six seven eight nine ten eleven); @hash{@a}=(0..$#a); @sorted=sort { $hash{$a}<=>$hash{$b} } keys %hash;

    mr.nick ...

Re: Re: Re: Removing Duplicates in an array?
by Hofmator (Curate) on Jun 26, 2001 at 18:17 UTC

    nice solution, but you could still be doing a lot of unnecessary data copying - depending on what is stored in @array - so:

    my %unique; @unique{@list} = (); @list = keys %unique;

    With the cookbook method you have of course the benefit of being able to get a count of the number of occurences ...

    -- Hofmator