in reply to generating combinations of elements of an arbitrary number of arrays
A fun alternative that uses glob:
use strict; use warnings; my @lists = ( [ qw/A B C D E F/ ], [ qw/1 2 3 4 5 6/ ], [ qw/apple orange pomegranate grape/ ], [ qw/wolf lion dog cat cow ape whale/ ], ); my @ranges = map { [ 0..$#$_ ] } @lists; my $glob_string = join '\\ ', map { '{'.join(',', @$_).'}' } @ranges; my @results; while (glob($glob_string)) { my $i = 0; push(@results, [ map { $lists[$i++][$_] } split ]); } print(join(' ', @$_), $/) foreach @results;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: generating combinations of elements of an arbitrary number of arrays
by ikegami (Patriarch) on Mar 15, 2005 at 23:03 UTC |