in reply to Array comparison for 3 arrays
use strict; use warnings; my @arrays = ( [0,1,2,3,4,5,6,7,8,9], [1,2,3,4,6,8,10,12,14], [1,2,3,5,7,9,11,13,15], ); my $min = my $max = $arrays[0][0]; my @lkups; for (0..$#arrays) { my $array = $arrays[$_]; my $lkup = \%{ $lkups[$_] }; for (@$array) { $min = $_ if $_ < $min; $max = $_ if $_ > $max; ++$lkup->{$_}; } } for my $i ($min..$max) { print(join("\t", $i, map { $_->{$i} ? 'yes' : '' } @lkups), "\n"); }
Alternatively, you could take advantage of the fact that the numbers are sorted and do something like a merge sort.
Update: Oops, I thought you wanted continuous indexes, but I doubt that now. Fix:
use strict; use warnings; my @arrays = ( [0,1,2,3,4,5,6,7,8,9], [1,2,3,4,6,8,10,12,14], [1,2,3,5,7,9,11,13,15], ); my %global_lkup; my @lkups; for (0..$#arrays) { my $array = $arrays[$_]; my $lkup = \%{ $lkups[$_] }; for (@$array) { ++$lkup->{$_}; ++$global_lkup{$_}; } } for my $i ( sort { $a <=> $b } keys(%global_lkup) ) { print(join("\t", $i, map { $_->{$i} ? 'yes' : '' } @lkups), "\n"); }
|
|---|