Hi John, Thanks a lot for the answer. But your code gives this instead: $VAR1 = [ { '2,3,jetsons' => 'george-1 foo-2' }, { '2,3,jetsons' => 'jane-1 bar-2' }, { '1,2,flintstones' => 'fred-1 foo-2' }, { '1,2,flintstones' => 'barney-1 bar-2' } ];
Please correct me if I'm wrong in understanding your code like this: __BEGIN__ my $res = hoa2aoh_yours($HoA); print Dumper $res; sub hoa2aoh_yours { my ($HoA) = @_; my $AoH; while ( my ( $key, $val ) = each %$HoA ) { push @$AoH, map +{ $key => $_ }, @$val; } return $AoH; } __END__ Let me give you another simpler example, given this my $HoA2 = { 'flintstones' => [ "fred", "barney" ], 'jetsons' => [ "george", "jane"], }; It should return this: $VAR1 = [ { 'flintstones' => 'fred', 'jetsons' => 'george' }, { 'flintstones' => 'fred', 'jetsons' => 'jane' }, { 'flintstones' => 'barney', 'jetsons' => 'george' }, { 'flintstones' => 'barney', 'jetsons' => 'jane' } ]; The very first example still holds, it's just a bit more complex. --Gundala On 10/31/05, John W. Krahn <[EMAIL PROTECTED]> wrote: > > 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> > > >