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

Re: pushing onto array is not working as intended..

by kyle (Abbot)
on Apr 08, 2009 at 19:38 UTC ( #756435=note: print w/ replies, xml ) Need Help??


in reply to pushing onto array is not working as intended..

This line:

push @{$records}, %record;

...should be:

push @{$records}, \%record;

...as you have everywhere else.

Update: Actually, that's not going to do what you want either. Change them all to:

push @{$records}, { %record };

With what you have, you'll end up with an array of references to the same hash. You want to construct a new hash every time you push, and the above syntax will do that.


Comment on Re: pushing onto array is not working as intended..
Select or Download Code
Replies are listed 'Best First'.
Re^2: pushing onto array is not working as intended..
by ikegami (Pope) on Apr 08, 2009 at 21:23 UTC
    Seems to me you fixed the wrong line in your update. I consider
    %record = (); ... push @{$records}, { %record };
    much worse than
    my %record; ... push @{$records}, \%record;
Re^2: pushing onto array is not working as intended..
by spstansbury (Monk) on Apr 08, 2009 at 20:47 UTC
    Yes, that's exactly what I wanted.
    The syntax is NOT second nature yet...

    Thank you very much!

    Scott...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2015-07-28 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls