http://www.perlmonks.org?node_id=115125


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