Gundala Viswanath wrote: > Dear Sirs, Hello,
> I want to convert a HoA into AoH. Basically what it does > is to create a distinct hash for each pair of array element that comes > from different keys (see the example below). > > Please also note that the size of the hash and array maybe varying > in the input HoA. And also note that the element of the array is actually > a string that contain white space. > > Here is the example, given this HoA: > > my $HoA = { > 'flintstones' => [ "fred-1 foo-2", "barney-1 bar-2" ], > 'jetsons' => [ "george-1 foo-2", "jane-1 bar-2"], > }; > > > How can I convert them to an AoH > > my $AoH = [ # Desired results. > > { > 'flinstones' => "fred-1 foo-2", > 'jetsons' => "george-1 foo-2" > }, > { > 'flinstones' => "fred-1 foo-2", > 'jetsons' => "jane-1 bar-2" > }, > { > 'flinstones' => "barney-1 bar-2", > 'jetsons' => "george-1 foo-2" > }, > { > 'flinstones' => "barney-1 bar-2", > 'jetsons' => "jane-1 bar-2" > }, > > ]; my $AoH; while ( my ( $key, $val ) = each %$HoA ) { push @$AoH, map +{ $key => $_ }, @$val; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>