in reply to Re: enumeration, again...
in thread enumeration, again...
#!/usr/bin/perl use strict; my %set = ( 'foo' => [1, 2, 3], 'bar' => ["A", "B", "C"], 'biz' => ["Y", "Z"], ); my @keys = sort keys %set; my $rows = @keys - 1; my @RESULTSET = (); sub enumerate { my $row = shift; my @result = @_; my @row_data = @{$set{$keys[$row]}}; foreach my $data (@row_data) { # Base Case if ($row == $rows) { my $item; my @copy = (@result, $data); for (my $i; $i < @copy; $i++) { $item->{$keys[$i]} = $copy[$i]; } push @RESULTSET,$item; } # Recursive Case enumerate($row+1, (@result, $data)) if ($row < $rows); } } enumerate(0,()); foreach my $item (@RESULTSET) { foreach my $key (@keys) { print $key ." => ". $item->{$key} .", "; } print "\n"; }
|
|---|