Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I don't see any difference with or without weaken $wrapper;,what's it there for?

Where exactly?

How are you checking to see a difference?

$ perl -MDevel::Peek -MScalar::Util=weaken -le " sub fudge { my $f = s +ub { print 1; }; Dump($f); weaken $f; Dump($f); $f; } $f = fudge(); $ +f->(); Dump($f);" SV = IV(0x3f8d18) at 0x3f8d1c REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 2 FLAGS = (PADSTALE,PADMY,ANON,WEAKOUTSIDE,CVGV_RC) COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge) SV = IV(0x3f8d18) at 0x3f8d1c REFCNT = 1 FLAGS = (PADMY,ROK,WEAKREF) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 1 FLAGS = (PADSTALE,PADMY,RMG,ANON,WEAKOUTSIDE,CVGV_RC) MAGIC = 0x3fff2c MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) MG_OBJ = 0x3f8d1c COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge) 1 SV = IV(0x9c2e40) at 0x9c2e44 REFCNT = 1 FLAGS = (ROK) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 2 FLAGS = (PADSTALE,PADMY,RMG,ANON,WEAKOUTSIDE,CVGV_RC) MAGIC = 0x3fff2c MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge)

As you notice, REFCNT doesn't change :)

Yeah, that is not a use case for weaken, you use weaken when you have circular references, say

my $foo = { kid => { } }; $foo->{kid}{parent} = $foo; weaken $foo->{kid}{parent};

In reply to Re: What's the weaken here for? by Anonymous Monk
in thread What's the weaken here for? by PerlOnTheWay

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2014-12-28 10:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (180 votes), past polls