Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: intersection of N arrays

by AnomalousMonk (Bishop)
on Aug 24, 2020 at 04:32 UTC ( #11121022=note: print w/replies, xml ) Need Help??


in reply to Re^2: intersection of N arrays
in thread intersection of N arrays

c:\@Work\Perl\monks>perl use strict; use warnings; my %ids; sub intersect { my %count; my @ret; my $count = keys %ids; foreach my $key (keys %ids) { my %this; for (@{$ids{$key}}) { next if $this{$_}; $count{$_}++; $this{$_}++; if ($count{$_} == $count) { push @ret, $_; } } } undef %ids; return @ret; } $ids{'foo'} = [ qw(three four four five) ]; $ids{'bar'} = [ qw(three) ]; $ids{'zoo'} = [ qw(five four three) ]; print "[ ",join(', ',intersect)," ]\n"; __END__ [ three ]


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2020-10-23 11:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (238 votes). Check out past polls.

    Notices?