The output is:sub enumerate { my (%p) = @_; my @types = (keys %p); my $type = shift(@types); my @sub_result; if (@types) { my %x; foreach my $subtype (@types) { $x{$subtype} = $p{$subtype}; } (@sub_result) = enumerate(%x); } my @results; foreach my $data (@{$p{$type}}) { if (@sub_result) { foreach my $result (@sub_result) { my %x; foreach my $y (keys %$result) { $x{$y} = $result->{$y}; } $x{$type} = $data; push(@results, \%x); } } else { push (@results, { $type => $data }); } } return (@results); } my @sets = enumerate( "foo" => [1, 2, 3], "bar" => ["A", "B", "C"], "biz" => ["Y", "Z"], ); foreach my $set (@sets) { my @out; foreach my $key (sort keys %{ $set }) { push (@out, "$key => $set->{$key}"); } print join(", ", @out) . "\n"; }
[bmc@blah bmc]$ perl /tmp/test.pl |sort bar => A, biz => Y, foo => 1 bar => A, biz => Y, foo => 2 bar => A, biz => Y, foo => 3 bar => A, biz => Z, foo => 1 bar => A, biz => Z, foo => 2 bar => A, biz => Z, foo => 3 bar => B, biz => Y, foo => 1 bar => B, biz => Y, foo => 2 bar => B, biz => Y, foo => 3 bar => B, biz => Z, foo => 1 bar => B, biz => Z, foo => 2 bar => B, biz => Z, foo => 3 bar => C, biz => Y, foo => 1 bar => C, biz => Y, foo => 2 bar => C, biz => Y, foo => 3 bar => C, biz => Z, foo => 1 bar => C, biz => Z, foo => 2 bar => C, biz => Z, foo => 3 [bmc@blah bmc]$
In reply to enumeration, again... by cazz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |