graham@tcom.stc.co.uk (Graham Bardsley) (06/13/91)
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);
}
newt$ perl bug.pl
$i=0
newt$ perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.3 $$Date: 91/06/07 11:40:18 $
Patch level: 9
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of the GNU General Public License,
a copy of which can be found with the Perl 4.0 distribution kit.
newt$
--
Graham Bardsley,NT Europe Ltd,Oakleigh Road South,New Southgate,London, N11 1HB
..{uunet,mcsun}!ukc!stc!graham <graham@tcom.stc.co.uk> Tel: +44 81 945 3799
And compact ISO10021 address is probably something like:
I=G/S=Bardsley/OU=lon4021/O=stc telecommunications/P=stc plc/A=gold 400/C=GB
merlyn@iWarp.intel.com (Randal L. Schwartz) (06/14/91)
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'..."====/
graham@tcom.stc.co.uk (Graham Bardsley) (06/14/91)
In article <1991Jun13.184509.20813@iWarp.intel.com> merlyn@iWarp.intel.com (Randal L. Schwartz) writes: > >Gack. Looks like perfectly reasonable code to me. I often find >myself doing things like: > > next MAIN if $some_condition; # (go to next one, in this case exit) >... >Not a bug. A feature. And a nice one at that. Yup - I've made a fool of myself again, I had it in my head that it would loop and of course it doesn't; maybe I was thinking of redo after all.... Thanks. -- Graham Bardsley,NT Europe Ltd,Oakleigh Road South,New Southgate,London, N11 1HB ..{uunet,mcsun}!ukc!stc!graham <graham@tcom.stc.co.uk> Tel: +44 81 945 3799 Just:{$another=$_='Perl novice';tr/cenoiv/erhakc/if$i;next unless$i++;}print;')'