Tomte has asked for the wisdom of the Perl Monks concerning the following question:
In comp.lang.perl.misc it was asked (message-ID: <1109848552.496818.242290@o13g2000cwo.googlegroups.com>)
I've tried various cloning modules to clone a structure containing weak references.my reply isThis prints: y: 1 z: I've tried it using the Clone module and Clone::PP. Clone::PP does the same as Storable. Clone gives a segmentation fault. I'm using Perl 5.8.0 on Linux 2.4.20-8use Storable 'dclone'; use Scalar::Util qw(weaken isweak); my $x = 99; my $y = [ \$x ] ; weaken $y->[0]; $z = dclone $y; print "y: ", isweak $y->[0]; print "z: ", isweak $z->[0];
After a little bit of thought I'd say that's normal, to be expected behaviour: You're not cloning the weakend reference, but the the data it references, the reference in z[0], poiting to the clone of $x, is a completly new one, the data is cloned, not the reference. I may misunderstand the behaviour though...hmmm kind regards, Tom
Now I'm curious: Am I right? And if I'm right: Is it possible to clone references (Update preserving their "weakend-state")?
regards,
tomte
An intellectual is someone whose mind watches itself.
-- Albert Camus
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cloning (weak) references
by hardburn (Abbot) on Mar 03, 2005 at 15:27 UTC | |
Re: Cloning (weak) references
by simonm (Vicar) on Mar 03, 2005 at 22:15 UTC |
Back to
Seekers of Perl Wisdom