develooper Front page | perl.perl5.porters | Postings from March 2014

RE: [perl #121501] Empty code block {} causes syntax error(misparsed as anonymous hash constructor?) before 'sub'

Thread Previous | Thread Next
From:
Ed Avis
Date:
March 25, 2014 14:48
Subject:
RE: [perl #121501] Empty code block {} causes syntax error(misparsed as anonymous hash constructor?) before 'sub'
Message ID:
7E039918541B4C4183BFDB8F015C74306976DF@WCL-EXCH02.wcl.local
>Can you give an example of such an empty block not being a syntax
>error?

Hmm, you are right, C<{} my $x;> is also an error.
In that case this looks like a bug where the case of an empty block is not handled correctly.
Normally in the Perl grammar a block can contain zero or more statements.
It is quite legitimate to have C<if (foo) {}> or C<sub bar {}>.  Yet somehow when a block
appears by itself it has the restriction that it must be non-empty.

I think this is a bit fishy; in other C-like languages an empty block can appear in any
place where a nonempty one can.  Could that become true for Perl too?

-- 
Ed Avis <eda@waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

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