Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://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":



  • 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 admiring the Monastery: (5)
As of 2024-04-23 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found