in reply to Re^2: An iterator for (not "iterating") a recursive data structure.
in thread An iterator for (not "iterating") a recursive data structure.

++. It looks like I forgot to test my code for false values (it took me a while to see where they wouldn't work, it was the very last line where I iterate while the value is true).

Thanks for the correction, for some reason I'm still not sure I would have thought of it even nowadays. I suppose I don't really think about using the number of returned values when I'm expecting a scalar, rather than a list

  • Comment on Re^3: An iterator for (not "iterating") a recursive data structure.

Replies are listed 'Best First'.
Re^4: An iterator for (not "iterating") a recursive data structure.
by LanX (Saint) on Jul 09, 2019 at 08:46 UTC

      ... OK, I'll have to seriously train myself to use that idiom.

        To be fair, the semi predicate problem will still show up if you want an empty array to be a valid return value.

        But there are ways to fix it:

        • return an array ref hence a scalar
        • throw an exception via die and catch it with eval block (or better Try::Tiny )
        • do a goto to an external label named FINISHED or similar (totally undervalued option)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice