in reply to 2D array ALL combinations
Algorithm::Loops's NestedLoops would handle this nicely.
use Algorithm::Loops qw( NestedLoops ); my @AoA1 = ( [ 'a', 'b', 'c' ], [ 'd', 'e', '' ], [ 'f', 'g', '' ], [ 'h', '', '' ], ); my @AoA2 = NestedLoops(\@AoA1, sub { [ @_ ] } );
To use less memory:
use Algorithm::Loops qw( NestedLoops ); my @AoA1 = ( [ 'a', 'b', 'c' ], [ 'd', 'e', '' ], [ 'f', 'g', '' ], [ 'h', '', '' ], ); my @AoA2; my $iter = NestedLoops(\@AoA1); my @list; while (@list = $iter->()) { push @AoA2, [ @list ]; }
By the way, since you have two identical values in @{$AoA1[3]}, @AoA2 will contain many duplicates.
Untested.
Update: The above don't produce the results in the order you described. If the order matters, change
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 2D array ALL combinations
by Anonymous Monk on Jun 13, 2007 at 18:01 UTC | |
by ikegami (Patriarch) on Jun 13, 2007 at 20:15 UTC |