in reply to Generating all possible combinations from an AoA
my @results = (""); foreach my $subarray (@array) { my @tmp_results = (); my @subarray = @{ $subarray }; foreach my $tmp_result (@results) { foreach my $element (@subarray) { my $string = $tmp_result . $element; push @tmp_results, $string; } } @results = @tmp_results; } print join "\n", @results; print "\n";
The trick is in the overwritting of @results with @tmp_results at the end of the outer loop, as well as in initializing @results with a single empty list in order for concatenation to work further down.
This could probably be written with several map's, but it might become difficult to read.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating all possible combinations from an AoA
by choroba (Cardinal) on Apr 14, 2011 at 12:37 UTC | |
by Zarabozo (Sexton) on Sep 22, 2013 at 05:55 UTC |