Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!att!ucbvax!iWarp.intel.com!news From: merlyn@iWarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: next label not reported as a bad label in BLOCK Message-ID: <1991Jun13.184509.20813@iWarp.intel.com> Date: 13 Jun 91 18:45:09 GMT References: <1991Jun13.092118.308@tcom.stc.co.uk> Sender: news@iWarp.intel.com Reply-To: merlyn@iWarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 54 In-Reply-To: graham@tcom.stc.co.uk (Graham Bardsley) Nntp-Posting-Host: se.iwarp.intel.com In article <1991Jun13.092118.308@tcom.stc.co.uk>, graham@tcom (Graham Bardsley) writes: | | Perl doesn't complain that having a 'next' statement inside a plain block is | an invalid use of next. This has I think been a long-standing `feature' since | after finding a use of it in an old perl program of mine a bug has disappeared. | Since perl complains about bad label usage everywhere else shouldn't it also | complain about using next in this way? An example session is given below... | | Cheers. | | newt$ cat bug.pl | #! /usr/local/bin/perl | | $i=0; | lab: { | print "\$i=$i\n"; | $i++; | next lab if ($i < 10); | } Gack. Looks like perfectly reasonable code to me. I often find myself doing things like: MAIN: { ... ... redo MAIN if $some_condition; # (jump to top) ... ... last MAIN if $some_condition; # (exit) ... ... next MAIN if $some_condition; # (go to next one, in this case exit) ... ... redo; # do it again } as a way of writing C's more obscure: while (1) { ... ... ... } Not a bug. A feature. And a nice one at that. MAIN: { redo MAIN unless print "Just another Perl hacker,"; } -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/