in reply to Combinations / permutations... not even sure what this is called

use warnings; use strict; for my $color (qw(red blue)) { for my $size (qw(sm med lrg)) { for my $num (1..4) { print "$color-$size-$num\n"; } } }
  • Comment on Re: Combinations / permutations... not even sure what this is called
  • Download Code

Replies are listed 'Best First'.
Re^2: Combinations / permutations... not even sure what this is called
by ikegami (Patriarch) on Oct 29, 2011 at 05:31 UTC

    If the N is dynamic, one can use Algorithm::Loops's NestedLoops.

    use Algorithm::Loops qw( NestedLoops ); my @arrays = ( [qw( red blue )], [qw( sm med lrg )], [ 1..4 ], ); NestedLoops( \@arrays, sub { print(join('-', @_), "\n"); }, );