> Using parallel arrays to store related data is not a good idea imho.

I wanna ask for long... so what is IMHO and RTFM ??


> I would use an (anonymous) array of hashes here:
> 
>     my $persons = [ { ID => 'Foo', COUNTRY => 'UK', GENDER => 'F' },
>                     { ID => 'Bar', COUNTRY => 'US', GENDER => 'M' },
>                     { ID => 'Bla', COUNTRY => 'HK', GENDER => 'M' },
>                     { ID => 'Bob', COUNTRY => 'HK', GENDER => 'F' }
>                   ];

Actually, the arrays are picked up from 'files' with their names.
like : open fh,... while... read... push @this_arr, $_ ... close(fh)
So to forms arrays... I think I know how to take care of this.

But is there any quick way to transform HOA to AOH ? I suggest this :

sub HoA2AoH
{ my %hash = @_; my @ret = ();
 my @keys = keys(%hash);

 for my $round (0..$#{$hash{$keys[0]}}) 
        ## Thanx 2 those folks teach me $#{$...} again ##

 { my %tempHash = ();
   for my $KEY(keys(%hash)) 
      { $tempHash{$KEY} = $hash{$KEY}[$round] }
   push @ret, \%tempHash;
 }
  return @ret
}

Any comment ? Any faster ways ?


Rgds,
Connie


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to