Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Bewildering perl parser bug

Reply
Thread Tools

Bewildering perl parser bug

 
 
kj
Guest
Posts: n/a
 
      12-14-2007


The following demo code causes the warning "Useless use of a constant
in a void context":

use strict;
use warnings;

{ ; package ABC; 1; }

sub foo {}

foo ABC->xyz, 2;

__END__

....because perl parses the last line as

ABC->foo->xyz, 2;

That's annoying enough, but what sends me for a loop is that if I
change the block

{ ; package ABC; 1 }

to

{ ; package PQR; 1 }

now the last line gets parsed as foo( ABC->xyz, 2 ), as any
reasonable, red-blooded parser would.

Now, why on earth would that "package ABC" statement confuse the
parser???

Of course, in this case I can clue in the parser by changing the
last line to

foo( ABC->xyz, 2 );

but this fix makes me uneasy, because it seems fixing the symptom
and not the cause, leaving me wondering about what else in the file
the parser will mess up (in fact this parsing error would have not
have been visible until runtime if the second argument to foo had
been a 1 or a 0 instead of a 2, because perl does not protest when
it finds either of those two values in a void context).

If there's a way to clue-in the parser that is closer to the source
of the error, please let me know.

TIA!

kj




--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
 
Reply With Quote
 
 
 
 
kj
Guest
Posts: n/a
 
      12-14-2007

Sorry, I neglected to specify the version of perl I'm using:

% perl -v

This is is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

...


kj


--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-14-2007
kj <(E-Mail Removed)> wrote:
> The following demo code causes the warning "Useless use of a constant
> in a void context":
>
> use strict;
> use warnings;
>
> { ; package ABC; 1; }
>
> sub foo {}
>
> foo ABC->xyz, 2;
>
> __END__
>
> ...because perl parses the last line as
>
> ABC->foo->xyz, 2;
>
> That's annoying enough, but what sends me for a loop is that if I
> change the block
>
> { ; package ABC; 1 }
>
> to
>
> { ; package PQR; 1 }
>
> now the last line gets parsed as foo( ABC->xyz, 2 ), as any
> reasonable, red-blooded parser would.
>
> Now, why on earth would that "package ABC" statement confuse the
> parser???


See the discussion of indirect object syntax in perldoc perlobj.

The previously defined subroutine foo primes perl to recognize subroutine
calls without parentheses. The previously defined package ABC primes perl
to recognize indirect object syntax calls for ABC. Apparently, the latter
takes precedence over the former.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
perl-parser? or a perl 2 java converter? Perl Misc 1 10-12-2004 11:41 AM
XML Parser VS HTML Parser ZOCOR Java 11 10-05-2004 01:58 PM
XMLparser: Difference between parser.setErrorHandler() vs. parser.setContentHandler() Bernd Oninger Java 0 06-09-2004 01:26 AM
XMLparser: Difference between parser.setErrorHandler() vs. parser.setContentHandler() Bernd Oninger XML 0 06-09-2004 01:26 AM



Advertisments