SPUG: Using last in non-loop blocks
Yitzchak Scott-Thoennes
sthoenna at efn.org
Thu Apr 22 19:51:46 CDT 2004
On Thu, Apr 22, 2004 at 08:02:50PM -0400, Jack Foy <jack at gehennom.net> wrote:
> Andrew Sweger wrote:
> 'if' (and 'unless') blocks are the exception to that rule -- unlike all
> other blocks, they are not one-time loops. (See page 123 of PP3.)
For(each)?, while, and bare blocks are more the exception; any
other block won't use next/last/redo: sort, do, grep, map, sub,
eval, &-prototype blocks, and continue (in a sense, anyway) all
have blocks that don't associate with next/last/redo (though
many of them will warn if you leave that way, control still
passes to the end of a "real" block (with another warning if
there wasn't a "real" block).
The behavior of eval is somewhat inconsistent this:
$ perl -we'eval { print "1"; last; print "2" }; print "3"'
Exiting eval via last at -e line 1.
13
$ perl -we'{eval { print "1"; last; print "2" }; print "3"}'
Exiting eval via last at -e line 1.
1
$ perl -we'{eval { print "1"; last; print "2" }; print "3"} print "4"'
Exiting eval via last at -e line 1.
14
Why 13 in one case and 14 in the other? And where's the
"Can't "last" outside a loop block" warning?
More information about the spug-list
mailing list