home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!netcom.com!lgolding
- From: lgolding@netcom.com (Laurence J. Golding)
- Subject: Re: bug with "last"
- Message-ID: <1993Jan11.175416.3503@netcom.com>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <cameron-930111155241-1-06364@fuligin>
- Date: Mon, 11 Jan 1993 17:54:16 GMT
- Lines: 46
-
- cameron@cs.unsw.oz.au writes:
-
- >This loop runs three times.
-
- > for (('a','b','c'))
- > { print "\$_ is '$_'\n";
- > { last; }
- > }
-
- >Surely it shouldn't? This is perl 4.035.
-
- I believe this behavior is correct (BTW, it does the same thing in 4.019),
- but I can see why it looks like a bug. The "problem" seems to be in the
- description of "last" on p.95 of the Camel book. There we read:
-
- Within the BLOCK of any compound loop statement, you may use ...
- last
- last LABEL
- ... If the LABEL is omitted, the loop control statement refers to
- the innermost enclosing loop.
-
- Now, in your example, the "{last;}" certainly does not look like a loop,
- and the "for" certainly does look like the innermost enclosing loop. So it
- appears that the book should read:
-
- ... If the LABEL is ommitted, the loop control statement refers to
- the innermost enclosing _block_.
-
- Either of these constructs works:
-
- for (('a','b','c'))
- {
- print "\$_ is $_\n"; last;
- }
- or
- MY_LABEL:
- for (('a','b','c'))
- {
- print "\$_ is $_\n"; {last MY_LABEL;}
- }
-
- Can anyone verify this speculation on my part?
- --
- Laurence J. Golding
- lgolding@netcom.com
- (510)490-3663
-