Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Code requested for array intersection count

by Fletch (Chancellor)
on Jun 09, 2003 at 15:25 UTC ( #264353=note: print w/replies, xml ) Need Help??


in reply to Code requested for array intersection count

Strictly speaking he doesn't want the intersection. He wants to put the elements from @array_2 into a bag (Set::Bag) but only if they're present in @array_1.

my %wanted = map { $_, 1 } @array_1; my $bag = Set::Bag->new( ); foreach( @array_2 ) { $bag->insert( $_ => 1 ) if $wanted{ $_ }; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://264353]
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-13 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (75 votes). Check out past polls.

    Notices?