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.
|
|---|
| 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 (Beadle) on Mar 07, 2010 at 13:02 UTC |