SPUG: Using last in non-loop blocks
Asim Jalis
asim at pair.com
Thu Apr 22 19:05:17 CDT 2004
I meant "a block that is *NOT* part of a construct". I keep
forgetting to type "not" periodically. This is of course much
more dangerous in programs than in e-mail messages. -- Asim
On Thu, Apr 22, 2004 at 07:50:28PM -0400, Asim Jalis wrote:
> Perhaps when the documentation says "a block by itself" it means
> a block that is part of a construct such as "if".
>
> So this throws an error as you observe:
>
> /usr/home/asim> perl -e 'if(1){ print "1\n"; last; print "2\n"; }
> '
> 1
> Can't "last" outside a loop block at -e line 1.
>
> But the following works just fine, and breaks out of the block
> before printing "2", without an error.
>
> /usr/home/asim> perl -e '{ print "1\n"; last; print "2\n"; }
> '
> 1
>
>
> Asim
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org
More information about the spug-list
mailing list