in reply to Generating all possible combinations from an AoA

Here's my uber-inelegant serialized approach... If you don't care about the order that every combination is created: (btw, I renamed @array to be @arrays)...
my ($carry, @tallykeeper) = map 0, @arrays, 0; #gets rid of warnings.. +. w/strictures while (!$carry) { $carry = 1; for my $dx (0 .. $#arrays ) { print $arrays[$dx]->[$tallykeeper[$dx]]; $tallykeeper[$dx] += $carry; if ($tallykeeper[$dx] < @{$arrays[$dx]}) { $carry = 0; }else{ $tallykeeper[$dx] = 0; } } print "\n"; }
OR if you MUST have it in that order you could reverse the order of your array lists, or with my solution use this solution:
my ($carry, @tallykeeper) = map 0, @arrays, 0; #gets rid of warnings.. +. while (!$carry) { $carry = 1; my $combostr = ""; for my $dx (reverse 0 .. $#arrays ) { $combostr .= $arrays[$dx]->[$tallykeeper[$dx]]; $tallykeeper[$dx] += $carry; if ($tallykeeper[$dx] < @{$arrays[$dx]}) { $carry = 0; }else{ $tallykeeper[$dx] = 0; } } $combostr = reverse $combostr; print "$combostr\n"; }

Okay mine are ultra lame... but it was fun to try to make a generic solution that worked for everything possible array of arrays...

--Ray