develooper Front page | perl.perl5.porters | Postings from February 2008

Re: [perl #50742] goto error?

Thread Previous | Thread Next
From:
Abigail
Date:
February 12, 2008 03:49
Subject:
Re: [perl #50742] goto error?
Message ID:
20080212114920.GC2832@abigail.be
On Tue, Feb 12, 2008 at 11:36:26AM +0000, Dave Mitchell wrote:
> On Tue, Feb 12, 2008 at 12:38:03AM -0800, ???????????? wrote:
> > I'm afraid there's something wrong in the goto parsing of Perl.
> > Please kindly confirm.
> > 
> > When I run the program below;
> > 
> > 	#! /bin/perl -w
> > 	# gotoTest.pl
> > 
> > 	goto FIN if 1;
> > 
> > 	print "skipped \n";
> > 	&sub_routine;
> > 
> > 	FIN:
> > 
> > 	sub sub_routine {
> > 		print "skipped 2\n";
> > 	}
> > 
> > The error returns;
> > 
> > 	C:\>gotoTest.pl
> > 	syntax error at C:\gotoTest.pl line 11, near "sub sub_routine "
> > 	Execution of C:\gotoTest.pl aborted due to compilation errors.
> 
> Although its a bit nit-picky, this is actually correct.
> Syntactically, a goto LABEL is an optional prefix to a statement.
> 
> A sub definition is not a statement, so you can't prefix it with a label.
> That's why 'Foo: ;' worked: you were labelling the null statement ';'


Yeah, that's what I first thought as well. But:

    $ perl -wce 'LABEL:'
    -e syntax OK
    $

Apparently, perl will infer a null statement in this case, as deparsing
shows:

    $ perl -MO=Deparse -wce 'LABEL:'
    BEGIN { $^W = 1; }
    LABEL: ;
    -e syntax OK
    $


Perhaps perl should do this as well in the case of 'LABEL: sub foo { ... }'.




Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About