Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: to pick the common element in the array

by dorko (Parson)
on Oct 17, 2008 at 13:28 UTC ( #717730=note: print w/replies, xml ) Need Help??

in reply to to pick the common element in the array

Personally, I like List::Compare:
use strict; use warnings; use List::Compare; use Data::Dumper; my @array1=('a','2','3','2'); my @array2=('1','2','3','2'); my $lc = List::Compare->new(\@array1, \@array2); # Get those items which appear at least once in both lists (their inte +rsection). my @intersection = $lc->get_intersection; print Dumper \@intersection;
Also, use strict; and use warnings; caught the typos you made in defining the arrays.



-- Yeah, I'm a Delt.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://717730]
[marto]: Corion, pretty much. How are things? You were at LPW?
[Corion]: marto: Yep, but I didn't make it up north, sorry ;)
[Corion]: But LPW was enjoyable, even though it's always a bit hectic due to cramming everything into one day

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2016-12-07 09:23 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (125 votes). Check out past polls.