klash has asked for the wisdom of the Perl Monks concerning the following question:
I want to copy a nested data structure. The FAQ tells me:
The Data::Dumper module on CPAN is nice for printing out data structures, and FreezeThaw for copying them. For example:
use FreezeThaw qw(freeze thaw); $new = thaw freeze $old;Where $old can be (a reference to) any kind of data structure you'd like. It will be deeply copied.
However, the following program:
gives the following output:use FreezeThaw qw(freeze thaw); use Data::Dumper; $hashref = { a => {}, b => {} }; print Dumper($hashref); $copy = thaw freeze $hashref; print Dumper($copy);
$VAR1 = { 'a' => {}, 'b' => {} }; $VAR1 = 1;What's the problem?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: deep copy of nested data structure
by autark (Friar) on Nov 22, 2000 at 13:54 UTC | |
Re: deep copy of nested data structure
by davorg (Chancellor) on Nov 22, 2000 at 14:12 UTC | |
Re: deep copy of nested data structure
by arturo (Vicar) on Nov 22, 2000 at 20:50 UTC | |
Re: deep copy of nested data structure
by little (Curate) on Nov 22, 2000 at 13:45 UTC |
Back to
Seekers of Perl Wisdom