Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: to pick the common element in the array

by dorko (Prior)
on Oct 17, 2008 at 13:28 UTC ( [id://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.

Cheers,

Brent

-- Yeah, I'm a Delt.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-25 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found