I'd define my own custom sub cross(&@@) sub cross(&\@\@) which does the "nasty" stuff in the inside after calling cross {$a.$b} @a,@a
| [reply] [d/l] [select] |
use strict;
use warnings;
use Data::Dump qw/pp dd/;
use 5.12.0;
# https://perlmonks.org/?node_id=11121968
sub cross(&\@@) {
my ( $code, $a_a, @b ) = @_;
#warn pp $code, $a_a,\@b;
map {
$a = $_;
map { $b=$_; &$code } @b;
} @$a_a;
}
my @a = 1..3;
my @b = 4..6;
my @c = 7..9;
pp
cross { $a.$b } @a,
cross { $a.$b } @b,@c;
(
147,
148,
149,
157,
158,
159,
167,
168,
169,
247,
248,
249,
257,
258,
259,
267,
268,
269,
347,
348,
349,
357,
358,
359,
367,
368,
369,
)
| [reply] [d/l] [select] |
use strict;
use warnings;
use List::MapMulti;
use Data::Dump 'pp';
my @a = 1..3;
my @b = 4..6;
my @c = 7..9;
pp mapm { $_[0] . $_[1] . $_[2] } \@a, \@b, \@c;
It can also be used as an iterator:
use strict;
use warnings;
use List::MapMulti 'iterator_multi';
use feature 'say';
my @a = 1..3;
my @b = 4..6;
my @c = 7..9;
my $iter = iterator_multi( \@a, \@b, \@c );
while ( my ( $a, $b, $c ) = $iter->() ) {
say $a, $b, $c;
}
| [reply] [d/l] [select] |