Michele Dondi writes: > Speaking of subs, and especially recursive ones which have been > mentioned en passant earlier, I have another question "of mine": I > know that in the vast majority of cases this won't be useful in any > way, but in the body of a (possibly anonymous) sub/block, will there > be some sort of identifier to refer to itself? I mean, in such a way > to be able create anonymous recursive functions. In Perl5 it's doable > by means of some trickery that involves an assignment, anyway.
It used to be &_. But that's changing now to be aliased to the slurpy block if one exists, and to the target sub of a wrapper. The new alternative is MY.sub. I suppose that could return the current actual sub, so if you're using a pointy sub you have to say MY.block or something. But it's one of those two. > Thinking of it better lexicals will be in package MY, right, so a possibly > not too out of question choice may be MY::_self (with underscore to avoid > unwanted collisions with user stuff). Something like (hopefully): > > print sub -> $n { > # Admittedly stupid example! > return $n if $n<=1; > MY::_self($n-1) + MY::_self($n-2); > }.(10); You have a redundancy there: "sub" and -> both mean the same thing, so use one or the other. If you use "sub", the argument list has to be parenthesized. Luke