http://www.perlmonks.org?node_id=11121022


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:  <%-{-{-{-<