in reply to Printing from three arrays

If you aren't doing anything else with them, just loop over the elements themselves instead of the indices. The innermost loop will loop most quickly, of course. So:

#!/usr/bin/env perl use strict; use warnings; my @array1 = (1, 2, 3); my @array2 = (qw/a b c/); # Enough to test my @array3 = (qw/I II III/); for my $alpha (@array2) { for my $roman (@array3) { for my $arabic (@array1) { print "$arabic,$alpha,$roman\n"; } } }

Replies are listed 'Best First'.
Re^2: Printing from three arrays
by daxim (Curate) on Sep 26, 2019 at 10:37 UTC
    Nested loops become unwieldy when you have many arrays. With a suitable module it does not matter how many dimension the input has:
    use 5.010; use Set::Scalar qw(); my $iter = Set::Scalar->cartesian_product_iterator( map { Set::Scalar->new(@$_) } [1, 2, 3], [qw/a b c/], [qw/I II III/], ); while (my @m = $iter->()) { say "@m"; }
    There are numerous alternatives: https://metacpan.org/search?q=cartesian+product
    Bonus:
    use v6; .say for cross (1, 2, 3), <a b c>, <I II III>