Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Array of Hashes

by hippo (Canon)
on Feb 07, 2019 at 13:18 UTC ( #1229547=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1229547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2019-03-27 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (125 votes). Check out past polls.

    Notices?