http://www.perlmonks.org?node_id=176234


in reply to Re: Re: sub and anonymous sub
in thread sub and anonymous sub

I'll answer only to 1st item, because I see 2nd already resolved.

As best of my understanding, yes, ref count for $depth is increased when "sub recurse" is compiled. And if, say, we compiled anonymous sub as my $r=sub{$depth} and then $r goes away due to refcounting, I see that ref count for $depth will be decreased once (even if $depth was used several times inside that sub).

Let me note that I just checked "perlsub" and see exactly your question explained at the section "Persistent Private Variables"

Best wishes,
Courage, the Cowardly Dog.
PS. Something fishy is going on there, or my name is Vadim Konovalov. And it's not.