Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: removing duplicate entries from an array

by kirbyk (Friar)
on Nov 07, 2005 at 20:51 UTC ( #506523=note: print w/ replies, xml ) Need Help??


in reply to removing duplicate entries from an array

Quick and dirty? How about:

my %seen; my @ABC; for my $element (@XYZ) { next if $seen{$element}++; push @ABC, $element; } @XYZ = @ABC;
Of course, it's a huge waste to create the second array for a placeholder (even though that code is very easy to understand.) You probably want to delete the entries in place, using splice or array slices, if the array can possibly be of any length.

-- Kirby, WhitePages.com


Comment on Re: removing duplicate entries from an array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2015-07-06 02:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls