Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: finding the distinct elements in an array

by rafl (Friar)
on May 29, 2006 at 13:10 UTC ( #552306=note: print w/replies, xml ) Need Help??


in reply to finding the distinct elements in an array

For example using that code:

my %seen; my @distinct_elems = grep { !$seen{$_}++ } @array;

or maybe

my %seen = map { $_ => 1 } @array; my @distinct_elems = keys %seen;

The first example even gives you the number of occurence of each element.

Cheers, Flo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://552306]
help
Chatterbox?
[erix]: we aim to satisfy
[erix]: churches are good excuses for large-scale architecture -- which is nice
[marto]: not to be confused with Chvrches

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-07-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (431 votes). Check out past polls.