Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

•Re: Get All Duplicated Elements in an Array (Once, without shifting)

by merlyn (Sage)
on Oct 14, 2002 at 16:19 UTC ( [id://205138]=note: print w/replies, xml ) Need Help??


in reply to Get All Duplicated Elements in an Array (Once, without shifting)

Just grab them only the second time they're seen.
my @result = do { my %counter; grep ++$counter{$_} == 2, @input; };

-- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found