monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Note that the example of input sample ($hash) is simplified. In my production code it actually comes in form of HoAoA.use strict; use Data::Dumper; # The HoA below may come in varying # sizes: from "key1" to "key 50" my $hash = { 'key1' => [ 1, 2, 3, 4 ], 'key2' => [ 10, 20, 30 ], 'key3' => [ 100, 200, 300 ], }; # My code below is "hard-coded" # How can I change it to accomodate # dinamycally changing hash size above? my @val1 = @{$hash->{'key1'}}; my @val2 = @{$hash->{'key2'}}; my @val3 = @{$hash->{'key3'}}; foreach my $val1 (@val1) { foreach my $val2 (@val2) { foreach my $val3 (@val3) { print "$val1 - $val2 - $val3\n"; } } }
1 - 10 - 100 1 - 10 - 200 1 - 10 - 300 1 - 20 - 100 1 - 20 - 200 1 - 20 - 300 1 - 30 - 100 1 - 30 - 200 1 - 30 - 300 2 - 10 - 100 2 - 10 - 200 2 - 10 - 300 2 - 20 - 100 2 - 20 - 200 2 - 20 - 300 2 - 30 - 100 2 - 30 - 200 2 - 30 - 300 3 - 10 - 100 3 - 10 - 200 3 - 10 - 300 3 - 20 - 100 3 - 20 - 200 3 - 20 - 300 3 - 30 - 100 3 - 30 - 200 3 - 30 - 300 4 - 10 - 100 4 - 10 - 200 4 - 10 - 300 4 - 20 - 100 4 - 20 - 200 4 - 20 - 300 4 - 30 - 100 4 - 30 - 200 4 - 30 - 300
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating a Dynamic Nested Loops for HoA
by Zaxo (Archbishop) on Dec 06, 2005 at 11:04 UTC | |
by albert (Monk) on Dec 06, 2005 at 16:27 UTC | |
|
Re: Creating a Dynamic Nested Loops for HoA
by BUU (Prior) on Dec 06, 2005 at 10:30 UTC | |
|
Re: Creating a Dynamic Nested Loops for HoA
by bageler (Hermit) on Dec 06, 2005 at 17:46 UTC | |
|
Re: Creating a Dynamic Nested Loops for HoA
by injunjoel (Priest) on Dec 06, 2005 at 23:29 UTC |