in reply to Re: using the feature 'switch' in loops
in thread using the feature 'switch' in loops

The reason why I used 'for'instead of 'given' was because it was the first example in the documentation as mentioned in persyn, Switch statements. It says, I quote:

... The foreach is the non-experimental way to set a topicalizer. If you wish to use the highly experimental given , that could be written like this: ...
.

It was only after reading the specific page Switch that I realized that I was dealing with a masked loop statement. The perlsyn doesn't mention this behaviour or difference.

  • Comment on Re^2: using the feature 'switch' in loops

Replies are listed 'Best First'.
Re^3: using the feature 'switch' in loops
by Anonymous Monk on Jul 30, 2014 at 17:01 UTC

    You're correct about the documentation, at least for Perl v5.16 and up (in which the entire given/when/smartmatch feature is "experimental"), and Switch statements could mention the behaviour of last within a given for clarity.

    But last without a label always breaks out of the innermost loop, so I still don't find that behaviour surprising and your observation that "the 'last' statement in the switch statements controlled the flow within the switch statement" is not quite right, since in your examples you're not inside a "switch" (given), you're inside two for loops.

    The only argument one might make is that that behaviour is inconsistent and last should also break out of a given (but according to your original post you don't expect that behaviour).

    I don't understand what you mean about a "masked loop statement". Switch is deprecated and has nothing to do with Switch statements (given/when) except the shared name of the feature.

      After further reading I would agree that Switch Statements seems to imply that for is a "switch" statement, white actually a for used in this way is still just a for.

      P5P is always happy about doc patches :-)