theantler has asked for the wisdom of the Perl Monks concerning the following question:
Dear perl -gurus: i am new to perl and really have begun to love this stuff very quickly .. I have a data structure:
I have a function that pass this ref, and then read some data into the strucrture and push it onto an array several passes, that I then return a ref to .. But I end up with the last (pass) element in all places in the array .. the ref use the same memory again and again? How can I make the ref a new one in each pass? When I print it out I get the correct strings for each pass .. so it must be the push that creates a problem.my $room = ( { TEXT => $string, EXITS => $exits, THINGS => { %things }, ITEMS => { %items }, CMDS => { %cmds }, # EVENTS => \&events, } );
Please, anyone, how to approach this problem? Thanks .. ^^^theantler<<<foreach (@rooms) { ($rr->{TITLE}, $rr->{TEXT}, $rr->{EXITS}, $rr->{THINGS +}, $rr->{ITEMS}) = split ":", $_; push @a, $rr; }; return \@a;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: the ref use the same memory when i push structure onto array? Gahh .. please help me dear perl-gurus
by almut (Canon) on Mar 07, 2010 at 12:31 UTC | |
by theantler (Sexton) on Mar 07, 2010 at 13:02 UTC | |
Re: the ref use the same memory when i push structure onto array? Gahh .. please help me dear perl-gurus
by eric256 (Parson) on Mar 09, 2010 at 14:11 UTC |
Back to
Seekers of Perl Wisdom