Mailing List Archive

Can't do { last } while
This construct, legal in Perl 4, has become invalid in perl 5.001l:

% perl -we '$x=1; do { last if $x==1; $x++ } while $x<0'
Can't "last" outside a block at -e line 1.

This is a pity, since 'do {..} while' is the only sane way to get a
minimum-once loop.

Sorry, I didn't check the bug list - www.perl.com wasn't responding.

Ian
Re: Can't do { last } while [ In reply to ]
: This construct, legal in Perl 4, has become invalid in perl 5.001l:
:
: % perl -we '$x=1; do { last if $x==1; $x++ } while $x<0'
: Can't "last" outside a block at -e line 1.
:
: This is a pity, since 'do {..} while' is the only sane way to get a
: minimum-once loop.

Doesn't work in Perl 4 either:

Bad label: <null> at /tmp/perl-ea01552 line 1.

Larry
Re: Can't do { last } while [ In reply to ]
Larry Wall <lwall@scalpel.netlabs.com> wrote:

> : This construct, legal in Perl 4, has become invalid in perl 5.001l:

> : % perl -we '$x=1; do { last if $x==1; $x++ } while $x<0'
> : Can't "last" outside a block at -e line 1.

> : This is a pity, since 'do {..} while' is the only sane way to get a
> : minimum-once loop.

> Doesn't work in Perl 4 either:
> Bad label: <null> at /tmp/perl-ea01552 line 1.
> Larry

Hmm... it turns out what I was really testing in my tryout with perl 4
was effectively

perl -we '{ $x=1; do { last if $x==1; $x++ } while $x<0 }'

which is legal in both, although the extra level of lastage could be a
surprise maybe deserving of a supressible warning.

BTW, and nothing to do with anything, I just had, for a few minutes, a
bare </TABLE> in a CGI program - which confused the hell out me, mostly
since Netscape screws up royally if you miss a closing '</TABLE>'. I'm
becoming less convinced that "everything is legal" is good...

Ian