Loading ...
Sorry, an error occurred while loading the content.

question about HoA and array slices

Expand Messages
  • bike2ride
    Hi all let assume a hash of array like my %HoA = ( col_A = [ 3, 5, 7 ], col_B = [ 23.56, 25.75, 29.10 ], col_C = [ A , B , C ], ); Is there a way to
    Message 1 of 1 , Dec 5, 2006
    • 0 Attachment
      Hi all

      let assume a hash of array like

      my %HoA = (
      col_A => [ 3, 5, 7 ],
      col_B => [ 23.56, 25.75, 29.10 ],
      col_C => [ 'A', 'B', 'C' ],
      );

      Is there a way to slice the HoA so that I have a simultaneous hash
      access to all first elements of the single arrays addressed by the
      hash' keys col_A, col_B, col_C? With the further iteration on the
      second, third elements ...


      I could write

      foreach (0..2) {
      my $refH= getRec (\%HoA, $_);
      # do something
      }

      sub getRec ($$) {

      my ($refH, $i)= @_;

      my %h= ();
      my @sorted= sort keys %$refH;
      @h{@sorted}= map {$_->[$i]} @$refH{@sorted};
      return (\%h);
      }

      /
      Thanks
      gl
    Your message has been successfully submitted and would be delivered to recipients shortly.