Transforming HoA into AoH

2005-10-31 Thread Gundala Viswanath
Dear Sirs, 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

Re: Transforming HoA into AoH

2005-10-31 Thread John W. Krahn
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

Re: Transforming HoA into AoH

2005-10-31 Thread Xavier Noria
On Oct 31, 2005, at 9:56, Gundala Viswanath wrote: 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

Re: Transforming HoA into AoH

2005-10-31 Thread Xavier Noria
On Oct 31, 2005, at 12:34, Xavier Noria wrote: sub HoA_to_AoH { my ($HoA) = @_; my @keys = keys %{$HoA}; return [] if not @keys; my @AoH = (); my $nkeys = @keys; my $nvals = @{$HoA-{$keys[0]}}; my $iter = indexes($nvals, $nkeys); while (my $idxs = $iter-()) {

Re: Transforming HoA into AoH

2005-10-31 Thread Gundala Viswanath
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