"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