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

 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".

Replies are listed 'Best First'.
Re^3: Syntax for an array of hashes, with 2D array in hash value
by AnomalousMonk (Archbishop) on Mar 09, 2011 at 01:50 UTC
    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.)