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

last cant be used to exit blocks. Refer perldoc -f last.
Moreover use <code> tage to post codes

--Lakshmanan G.

The great pleasure in my life is doing what people say you cannot do.


Replies are listed 'Best First'.
Re^2: Can't "last" outside a loop block
by shmem (Chancellor) on Apr 02, 2009 at 13:49 UTC
    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.

      ...all of which is a pretext for the poor mans case/switch statement illustrated here

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