Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Array of Hashes

by hippo (Chancellor)
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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-09-30 09:12 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (160 votes). Check out past polls.