Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: intersection of N arrays

by Ido (Hermit)
on Jun 30, 2004 at 22:43 UTC ( [id://370932]=note: print w/replies, xml ) Need Help??


in reply to intersection of N arrays

perlfaq4 suggests:
@union = @intersection = @difference = (); %count = (); foreach $element (@array1, @array2) { $count{$element}++ } foreach $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference } +, $element; }
Based on that you could:
sub intersection{ my(%count,@res); for(map @$_,@_){$count{$_}++} for(keys %count){push @res,$_ if $count{$_}==@_} @res; } @a=intersection(\@b,\@c,\@d);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-23 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found