in reply to Re: Re: Removing Duplicate Array Elements!!!
in thread Removing Duplicate Array Elements!!!
If you are looking an efficient method to do this then try.
my %hash; @hash{@a} = (); @a = keys %hash;
But that only works, just as your example, for non-references as the keys of a hash can only be strings. If @a may contain references that you want to preserve then use
my %hash; @hash{@a} = @a; @a = values %hash;
This is slightly less efficient as it causes an extra copy of each element in @a
I generally write this as
@a = do { my %h; @h{@a} = @a; values %h }; # unique
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Removing Duplicate Array Elements!!!
by tachyon (Chancellor) on Sep 27, 2001 at 20:36 UTC | |
Re^4: Removing Duplicate Array Elements!!!
by littlemonk (Sexton) on Feb 03, 2011 at 10:22 UTC |
In Section
Seekers of Perl Wisdom