Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.
use 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];
This 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-8
my reply is
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


In reply to Cloning (weak) references by Tomte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found