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};
-
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.