home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7754 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.6 KB  |  57 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!netcom.com!lgolding
  3. From: lgolding@netcom.com (Laurence J. Golding)
  4. Subject: Re: bug with "last"
  5. Message-ID: <1993Jan11.175416.3503@netcom.com>
  6. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  7. References: <cameron-930111155241-1-06364@fuligin>
  8. Date: Mon, 11 Jan 1993 17:54:16 GMT
  9. Lines: 46
  10.  
  11. cameron@cs.unsw.oz.au writes:
  12.  
  13. >This loop runs three times.
  14.  
  15. >    for (('a','b','c'))
  16. >        { print "\$_ is '$_'\n";
  17. >          { last; }
  18. >        }
  19.  
  20. >Surely it shouldn't? This is perl 4.035.
  21.  
  22. I believe this behavior is correct (BTW, it does the same thing in 4.019),
  23. but I can see why it looks like a bug.  The "problem" seems to be in the
  24. description of "last" on p.95 of the Camel book.  There we read:
  25.  
  26.     Within the BLOCK of any compound loop statement, you may use ...
  27.             last
  28.             last LABEL
  29.     ... If the LABEL is omitted, the loop control statement refers to
  30.     the innermost enclosing loop.
  31.  
  32. Now, in your example, the "{last;}" certainly does not look like a loop,
  33. and the "for" certainly does look like the innermost enclosing loop.  So it
  34. appears that the book should read:
  35.  
  36.     ... If the LABEL is ommitted, the loop control statement refers to
  37.     the innermost enclosing _block_.
  38.  
  39. Either of these constructs works:
  40.  
  41.     for (('a','b','c'))
  42.     {
  43.         print "\$_ is $_\n"; last;
  44.     }
  45. or
  46.     MY_LABEL:
  47.     for (('a','b','c'))
  48.     {
  49.         print "\$_ is $_\n"; {last MY_LABEL;}
  50.     }
  51.  
  52. Can anyone verify this speculation on my part?
  53. -- 
  54. Laurence J. Golding
  55. lgolding@netcom.com
  56. (510)490-3663
  57.