|
|
| "be consistent" | |
| PerlMonks |
Re: 'Dynamic scoping' of capture variables ($1, $2, etc.) (localization of captures in recursions is buggy!)by LanX (Saint) |
| on Dec 16, 2012 at 21:03 UTC ( [id://1009094]=note: print w/replies, xml ) | Need Help?? |
|
I understand your problem, for my understanding "dynamically scoped" should mean localized such that the sum at the end shouldn't be 4=1+1+1+1 but 1+7777+666+55. but if you read the docs differently
you can see that the next match within the recursion sets $1 to another value. At least that's ATM my understanding of the designers intention. > a branch to a point within the same block no, no tail-head optimization in Perl! I will try to run some experiments tomorrow. UPDATE1: hmm, w/o recursion and with different strings it works like localized:
UPDATE2 you're right there is a bug in how recursive functions are handled:
in contrast explicitly different functions:
Perl 5.10 UPDATE3 the following shows that $1 is static per function, maybe they where implemented like closures.
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||