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

This works with numbers, how can you make it work with strings.

Replies are listed 'Best First'.
Re^3: intersection of N arrays
by AnomalousMonk (Archbishop) on Aug 24, 2020 at 04:32 UTC

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