Perl Programming/Keywords/last

Previous: kill Keywords Next: lc

The last keyword edit

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 edit

  last LABEL
  last EXPRESSION
  last

Examples edit

  LINE: while (STDIN) {
    last LINE if /^$/;  # exit when done with header
    #...
  }

See also edit

Previous: kill Keywords Next: lc