ideasuntouched has asked for the wisdom of the Perl Monks concerning the following question:

hi i want to know, how to get the unique elements of an array?

Replies are listed 'Best First'.
Re: array unique elements
by toolic (Bishop) on Apr 06, 2010 at 16:49 UTC
Re: array unique elements
by FunkyMonk (Bishop) on Apr 06, 2010 at 16:48 UTC
    1. Stick all the array elements into a hash (as the keys; the values should be a count of occurrences).
    2. Iterate over the keys in the hash and add each key to a new array if the count is one
    3. Profit!

    Or, why don't you show us what you've already tried?

    Update: I think I originally answered a different question :(

Re: array unique elements
by kennethk (Abbot) on Apr 06, 2010 at 16:54 UTC
      my %hash = map { $_ => 1 } @words; my @unique = keys %hash; this code is working for removing duplicates