Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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 ( [id://827227]=note: print w/replies, xml ) Need Help??


in reply to the ref use the same memory when i push structure onto array? Gahh .. please help me dear perl-gurus

That's the nature of references. They refer to some other thing which exists somewhere else.  If you copy just the reference (by pushing it onto the array), that copy will still refer to the same old thing.

You have to create a new data structure for each new set of info:

my ($title, $text, ...) = split /:/; push @a, { TITLE => $title, TEXT => $text, ... };

Also search CPAN for various modules that allow making deep copies of data structures.

  • Comment on Re: the ref use the same memory when i push structure onto array? Gahh .. please help me dear perl-gurus
  • Download Code

Replies are listed 'Best First'.
Re^2: the ref use the same memory when i push structure onto array? Gahh .. please help me dear perl-gurus
by theantler (Sexton) on Mar 07, 2010 at 13:02 UTC
    Dear almut, thanks for your answer. I thought maybe that perl knew the values into the structure had changed and so it incremented the ref memory or something like that. But it works now, wow .. this stuff is so great. I love it. I am very grateful I also always -sofar get a qualified answer, when I ask a question here .. what a great place! I love you guys. ^^^theantler<<<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-05-27 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found