411 REFERENCE · Wikibooks
Perl Programming/Keywords/last
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl kill lc Keywords
The last keyword
last is the same as break in C-like languages and is used to make the program immediately exit the current loop. Withou LABEL, the innermost loop is assumed. From Perl 5.18.0 onwards, it is possible to compute the LABEL during runtime by passing an EXPRESSION.
If a loop has a last command, the continue block is skipped.
last cannot be used to exit a block that returns a value (as it is the case with do {}, eval {}, or {}sub {}. It should not be used to exit a grep() or map() operation.
Syntax
last LABEL
last EXPRESSION
last
Examples
LINE: while (STDIN) {
last LINE if /^$/; # exit when done with header
#...
}
See also
continue
next
redo
Perl kill lc Keywords