You may want to use this simpler rewrite of the module's each_arrayref function. each_array is a superfluous wrapper around this function that uses prototypes to take references to arrays passed as parameters.
Its functionality is identical to the module version, except that it does no checking of the parameters it receives, and the iterator returned doesn't check that it has either no parameters or 'index'.
use strict;
use warnings;
sub each_array {
my @copy = @_;
my $i;
my $max;
for (map scalar @$_, @copy) {
$max = $_ unless defined $max and $max > $_;
}
sub {
return $i if @_ and shift eq 'index';
my $new_i = defined $i ? $i + 1 : 0;
return if $new_i >= $max;
$i = $new_i;
return map $_->[$i], @copy;
}
}
my @array1 = qw/ A B C /;
my @array2 = qw/ D E F G /;
my $iter = each_array(\@array1, \@array2);
while (my @values = $iter->()) {
printf "%d: %s\n", $iter->('index'), join ', ', map $_ // 'undef', @values;
}
output
0: A, D
1: B, E
2: C, F
3: undef, G
You could, of course, simply take the code for each_arrayref from the List::MoreUtils module. It is self-contained and will guarantee compatibility with your existing code.