develooper Front page | perl.perl5.porters | Postings from September 2014

[perl #122829] Flipflop under recursion

Thread Previous | Thread Next
Father Chrysostomos
September 23, 2014 01:13
[perl #122829] Flipflop under recursion
Message ID:
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #122829]
# in the subject line of all future correspondence about this issue. 
# <URL: >

perlop.pod states:

    Each ".." operator
    maintains its own boolean state, even across calls to a subroutine
    that contains it.

While that is true and well-known, what few know is that recursive calls to the containing subroutine do not share that boolean state with the outer call.  What’s weirder is that each recursion level maintains its own state.  So, for instance, if you have a function calling itself recursively to the fifth level, the flip-flop operator evaluated at that level will not use the same state again until that function is called to that level again.

I haven’t come up with an example of this weird behaviour yet, but I’ll try to post something in the next day or two.

My question is:  Is this behaviour intentional?  It doesn’t match my reading of the documentation.  And I can’t think of any use for it short of obfuscation.  I am inclined to think this is a bug.

Further, I have found a discrepancy in this operator, in that it returns the same scalar each time when the enclosing sub is not called recursively, but a different scalar each time when the enclosing sub *is* called recursively.

I was about to fix that discrepancy, when I realised that sharing the state between recursion levels would make the fix easier (the same change would fix both).


Father Chrysostomos

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