in reply to Syntax for an array of hashes, with 2D array in hash value

Also, try reading the following perldoc's for additional information:

  • Comment on Re: Syntax for an array of hashes, with 2D array in hash value

Replies are listed 'Best First'.
Re^2: Syntax for an array of hashes, with 2D array in hash value
by element (Novice) on Mar 08, 2011 at 07:38 UTC
     my $value = $objarray[72]{'apts'}[3][1]

    Thanks for the simple code, it works well.

    I did read about arrays of hashes in the suggested sources, but it's not quite trivial to step up from there to "an array of hashes, each storing a 2D array".

      The top level of the structure is an array, let's call it "objarray" ...
      my @objarray = ();
      ...(about 90 elements). Each element of "objarray" is a hash.
      my @objarray = ( { }, { }, ({ }) x 87, # 87 more elements... { }, );
      One of the hash's keys is called "apts".
      my @objarray = ( { 'apts' => '???', }, { 'apts' => '???', }, ({ 'apts' => '???', }) x 87, { 'apts' => '???', }, );
      The value of that key is a 2D array ... consisting of 2 columns and several rows.
      my @objarray = ( { 'apts' => [ [11,12], [13,14], [15,16], ], }, { 'apts' => [ [21,22], [23,24], [25,26], ], }, ({ 'apts' => '???', }) x 87, { 'apts' => [ [91,92], [93,94], [95,96], ], }, );
      >perl -wMstrict -le "my @objarray = ( { 'apts' => [ [11,12], [13,14], [15,16], ], }, { 'apts' => [ [21,22], [23,24], [25,26], ], }, ({ 'apts' => '???', }) x 87, { 'apts' => [ [91,92], [93,94], [95,96], ], }, ); ;; print 'elements in array: ', scalar @objarray; print $objarray[89]{'apts'}[2][1]; " elements in array: 90 96

      (I cheated a bit on the construction of the array and so could not use the indices in the OP, but you get the idea.)