last cant be used to exit blocks.
Wrong (well, half wrong ;-)
perl -wle '$x = 1; {$x = 2; last; $x = 3} print $x' 2
The documentation for last states that
"last" cannot be used to exit a block which returns a value such as "eval {}", "sub {}" or "do {}"
but it can be used to exit all other loop blocks, even bare blocks. But it can not be used to exit if/elsif/else blocks.
In reply to Re^2: Can't "last" outside a loop block
by shmem
in thread Can't "last" outside a loop block
by raghu_shekar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |