http://qs321.pair.com?node_id=264353


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{ $_ }; }