develooper Front page | perl.perl5.porters | Postings from October 2001

RE: [ID 20010930.005] interpolated BEGIN oddities

Thread Previous | Thread Next
From:
Richard Soderberg
Date:
October 18, 2001 02:38
Subject:
RE: [ID 20010930.005] interpolated BEGIN oddities
Message ID:
NAEKLNAAHLMBPMPNBMLEOELODPAA.rs@crystalflame.net
-----Original Message-----
> From: Michael G Schwern [mailto:schwern@pobox.com]
> Sent: Sunday, September 30, 2001 4:00 PM

> On Sun, Sep 30, 2001 at 01:56:35PM +0100, Hugo van der Sanden wrote:
> > Under perls at least from 5.005_03 to blead@12163, I get
> this oddity:
> >
> >   crypt% ./perl  -wle 'print qq;@{[ BEGIN { print "BEGIN" } ]};'
> >   BEGIN
> >   Can't call method "BEGIN" without a package or object
> reference at -e line 1.

[snip]

> If we define a foo() function:
>
> $ perl -wle 'sub foo { 42 }  print qq;@{[ foo { bless {} } ]};'
> Odd number of elements in hash assignment at -e line 1.
> 42
>
> it changes the whole characteristic of the parsing:
>
>     sub foo { 42; }
>     print "@{[ foo({ bless({}) }) ];}";
>
> BUT if we do it the other way around, no warning:
>
> $ perl -wle 'print qq;@{[ foo { bless {} } ]};;  sub foo { 42 }'
> 42
>
>     print "@{[do { bless {} }->foo];}";
>
>     sub foo { 42; }
>
> and it parses like it did originally.
>
> Now that's a problem.

For whoever finds this bug report in the future, the following two
statements parse differently.  They shouldn't.

perl -wle 'sub foo { 42 }  print qq;@{[ foo { bless {} } ]};'
perl -wle 'print qq;@{[ foo { bless {} } ]};;  sub foo { 42 }'

This would be a tough test case, too.

Did I get the two statements right?  Quite the interesting bug.

R.


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