Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Code requested for array intersection count

by tcf22 (Priest)
on Jun 09, 2003 at 15:16 UTC ( #264348=note: print w/replies, xml ) Need Help??


in reply to Code requested for array intersection count

Try using grep.
my @a1 = qw( A B ); my @a2 = qw( A B C D A D B A C ); foreach my $el(@a1){ my $count = grep /^$el$/, @a2; print "$el is in Array2 $count times\n"; }
produces
A is in Array2 3 times B is in Array2 2 times

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-08-09 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (54 votes). Check out past polls.

    Notices?