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

Re: [perl #50742] goto error?

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
February 12, 2008 03:42
Subject:
Re: [perl #50742] goto error?
Message ID:
20080212113626.GB18823@iabyn.com
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 ';'

-- 
"I do not resent criticism, even when, for the sake of emphasis,
it parts for the time with reality".
    -- Winston Churchill, House of Commons, 22nd Jan 1941.

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