develooper Front page | perl.perl5.porters | Postings from May 2015

Re: Premature freeing with "Non-eval closures don't need CvOUTSIDE"

Thread Previous | Thread Next
Christian Jaeger
May 6, 2015 22:36
Re: Premature freeing with "Non-eval closures don't need CvOUTSIDE"
Message ID:
2015-05-06 22:40 GMT+01:00 Eric Brine <>:

> On Wed, May 6, 2015 at 1:31 AM, Christian Jaeger <> wrote:
>> Since making a (local) function visible to itself creates a cycle,
>> Scalar::Util's "weaken" needs to be used.
> Hardly. You can use a package variable.

To retain the dynamically scoped variable within the nested closure it
still needs to get a lexical binding (just like in the fixed example with
weaken). And using dynamic scope with an otherwise functional program is
asking for oversights and thus bugs. But, fair point, it will avoid the
need for weaken, and make the program look visually (even if not
semantically) clean. *Except*, somehow this doesn't actually work, getting
at the local'ized binding from within the closure returns undef. See [1].


Or you can use __SUB__

Interesting, although this requires "use v5.16", so not usable everywhere
yet. It still also needs to be bound to a lexical for the inner closure,
but does make the code simpler (and probably a little faster). See [2].
Thanks for this tip.



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About