http://www.perlmonks.org?node_id=1229547


in reply to Array of Hashes

so I tested using sub getOneRow, which works as expected, proving the dereferencing is correct.

Unfortunately not. In each sub you are not pushing a hashref onto the array (as you should) but instead pushing a hash, so the array essentially becomes the hash. To fix, in your subs push the hashref on:

push @data, $rowref;

and in your calling routine iterate over each hashref rather than hash:

foreach $row (@data) {

Otherwise, please investigate placeholders now before little Bobby Tables comes to tea.

Replies are listed 'Best First'.
Re^2: Array of Hashes
by Ken_M (Initiate) on Feb 07, 2019 at 14:05 UTC

    Thanks - as in haukex's solution, pushing the ref worked.

    Placeholders aren't relevant here, because the sub will only be called once per script execution, but the single call may be from a number of different places in the main body.