Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • do {} while isn't a loop from which you can last, etc.. The relevant part of perlsyn(1) is:

    Note also that the loop control statements described later will NOT work in this construct, because modifiers don't take loop labels.

    The standard trick solution is to double-up the curlies, creating a block from which you can exit:

    do {{
      # ...
    }} while (...);

    Uuuuugly. That's the price you pay for having trailing modifiers. In perl5 at least ...

    --Nat

    • Thanks for the tip, yet I confess that this behavior violates the design principle of least astonishment. Perhaps I'm letting my Pascal heritage show a bit too much. The other wacky behavior is that the last jumps out of foo() back into bar(). I realize that next, last and redo are different spellings for goto. Still, I was surprised. In any case, I'm happy that someone had the foresight to recognize that this behavior might startle some users and to provide a warning to clue us in.

      This is one of the dusty

      • Welcome to the surprise of dynamic scope. Loop control is dynamically scoped, not lexically. When a last is encountered at runtime, the stack is popped until a scope in a last-able state is found. If you name your block and say last NAME, similar magic occurs.

        Yes, it is surprising.

        This is a legacy from Rift Valley Perl, I believe.

        --Nat

        • by jordan (120) on 2002.07.15 15:47 (#10644) Homepage Journal
          Google turns up no hits whatsoever for "Rift Valley Perl". There are a number of hits with "Rift Valley" and Perl in them, but nothing obvious.

          Can someone please enlighten me what "Rift Valley Perl" is?

          • It's a metaphor. Mankind's earliest upright-walking ancestors are supposed to have originated from the Rift Valley in Africa. Hence "Rift Valley Perl" was an allusion to the primitive ur-Perl around version 1.

            Yeah, I know, Dennis Miller's show was cancelled. Get a life, Torkington :-)

            --Nat