in reply to Re^2: Creating combinations using arrays
in thread Creating combinations using arrays
So use a recursive function!
rec_for([1..3],["a".."c"],[10..13]); my @tuple; sub rec_for { if (@_) { my $a_list = shift; for my $x (@$a_list) { push @tuple, $x; rec_for(@_); pop @tuple; } } else { print "tuple: @tuple\n"; } }
/usr/bin/perl -w /home/lanx/B/PL/PM/recursive_for.pl tuple: 1 a 10 tuple: 1 a 11 tuple: 1 a 12 tuple: 1 a 13 tuple: 1 b 10 tuple: 1 b 11 ...
Cheers Rolf
if you need the result in a %hash, just alter the routine to process key-value pairs
rec_for(a=>[1..3],b=>["a".."c"],c=>[10..13]);
|
|---|