Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Removing duplicates from an array

by cdarke (Prior)
on Jan 02, 2008 at 17:00 UTC ( [id://660011]=note: print w/replies, xml ) Need Help??


in reply to Removing duplicates from an array

To try to answer your update. The subroutine builds a hash using the elements of the input array as keys (the values are just set to 1, and not used). Since hash keys are unique, any duplicates will just overwrite the previous value. It then dumps the keys (using keys), and implicitly returns the resulting array. Use it thus:
my @no_duplicates = r(@original_array);

Replies are listed 'Best First'.
Re^2: Removing duplicates from an array
by alexm (Chaplain) on Jan 03, 2008 at 16:49 UTC
    my @no_duplicates = r(@original_array);
    Please, note that this method may not preserve the original order of the array values. But uniq function from List::MoreUtils does, as mentioned in perlfaq4 and PBP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://660011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found