in reply to cartesian product preserving order
Where you can change this line to do whatever you want with the combination:sub comb { my $s = shift; if (@_ == 1) { print "$s$_\n" for @{$_[0]}; return; } comb("$s$_",@_) for @{shift()}; } comb '',[qw(a b c)],[qw(1 2 3)],[qw(- + *)];
BrowserUK's solution is somewhat neater, but it's more a pull down approach, where all combinations are returned at once, rather than a push up approach, where only one combination is worked on at a time. You might as well use glob if you're going that route.if (@_ == 1) { dowhatever("$s$_") for @{$_[0]}; return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: cartesian product preserving order
by ikegami (Patriarch) on Jun 09, 2005 at 05:54 UTC | |
|
Re^2: cartesian product preserving order
by Limbic~Region (Chancellor) on Jun 09, 2005 at 12:48 UTC |