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