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

Re: [perl #21575] Bug with print( followed by a newline

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
March 14, 2003 08:55
Subject:
Re: [perl #21575] Bug with print( followed by a newline
Message ID:
20030314175453.6ed799f6.rgarciasuarez@free.fr
"Philippe 'BooK' Bruhat (via RT)" <perlbug-followup@perl.org> wrote:
> The following short piece of code is broken.
> 
> $ cat print.pl
> #!/usr/bin/perl
> my %data = ( foo => 'bar' );
> print(
> $data{foo});
> 
> The problem with this short script is that it prints nothing,
> no matter which perl you use (it breaks for me with 5.6.1, 5.8.0
> and bleadperl).

Cute.

> If we look at what the compiler understood, everything looks normal:
> 
> $ perl5.6.1 -MO=Deparse print.pl
> print.pl syntax OK
> my(%data) = ('foo', 'bar');
> print $data{'foo'};
> 
> $ perl5.8.0 -MO=Deparse print.pl
> print.pl syntax OK
> my(%data) = ('foo', 'bar');
> print $main::data{'foo'};

That "main::" isn't normal. %data is lexical.

That's a parsing problem. While trying to disambiguate between the
filehandle/indirect object "$data" and the value "$data{foo}" the
parser gets confused and forgets to look in the pad. Sticking a
STDOUT corrects the problem.

(I have an impression of déjà vu : anyone remembers a recent bug report
about a similar confusion ?)

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