in reply to Use of 'last' within single-line while loops

last will exit the inner-most loop statement. Those are:

Expressions with loop statement modifiers are not considered by last. The same goes for loop-like functions. These include the following:

All loop statements have braces, but not all braces are related to loop statements. The following are examples that aren't:


If you want a warning for the code you used, take a look at perlcritic. If it doesn't yet have a rule for it, you could create one.

Replies are listed 'Best First'.
Re^2: Use of 'last' within single-line while loops
by choroba (Cardinal) on Mar 21, 2018 at 06:52 UTC
    > Expressions with loop statement modifiers are not considered by last.

    choroba@still ~ $ perl -wE 'L: for my $x (qw(a b c)) { say("$x$_"), la +st for 1,2,3}' a1 b1 c1 choroba@still ~ $ perl -wE 'L: for my $x (qw(a b c)) { say("$x$_"), la +st L for 1,2,3}' a1

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      wut. Well that's not right. Of course, it can't be fixed now without breaking code.

Re^2: Use of 'last' within single-line while loops
by hurricup (Pilgrim) on Mar 21, 2018 at 07:34 UTC

    Correction, works fine with for statement modifier

    say $_ and last for 1,2,3