in reply to Re: Can't "last" outside a loop block
in thread Can't "last" outside a loop block

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.

Replies are listed 'Best First'.
Re^3: Can't "last" outside a loop block
by Bloodnok (Vicar) on Apr 02, 2009 at 15:00 UTC
    ...all of which is a pretext for the poor mans case/switch statement illustrated here

    A user level that continues to overstate my experience :-))