And so on for many more iterations... So, what I think is that I have an anonymous array of a hash of hashes? If the first value is an array, I'd like to do a foreach loop over it to get at the other values. Try as I might I'm not succeeding in unravelling the $results array in perl code. I can access individual elements as follows:print Dumper ($results); $VAR1 = [ { 'somevar1' => { 'othervar1' => 'somevalue' 'othervar2' => 'somevalue' } 'somevar2' => { 'othervar1' => 'somevalue' 'othervar2' => 'somevalue' } }, { 'somevar1' => { 'othervar1' => 'somevalue' 'othervar2' => 'somevalue' } 'somevar2' => { 'othervar1' => 'somevalue' 'othervar2' => 'somevalue' } } ];
But - this does not solve the problem in that it is necessary to know how many elements of the array there are in order to access all such values. Attempting to dereference the array with$results->[0]{'somevar1'}{'othervar1'}
Always produces a result of 1 for $no_elements_in_array even when there are lots of elements (basically does not work as expected). Clearly I am missing something in working with this data structure. My first question is how do I get at the number of elements (ie. first level hashes) in the array? Then at least I can write a for loop as follows and solve the immediate problem:@dereferenced_array = @{results}; $no_elements_in_array = @dereferenced_array;
Second, why does my attempt to get at the array fail? Thanks Colinfor ($i = 0; $i < $no_elements_in_array; i++) { $value = $results->[i]{'somevar1'}{'othervar1'}; print "$value\n"; }
In reply to accessing data structure by CColin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |