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

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

Thread Next
From:
perlbug-followup
Date:
March 14, 2003 08:36
Subject:
[perl #21575] Bug with print( followed by a newline
Message ID:
rt-21575-53639.19.5514743866347@bugs6.perl.org
# New Ticket Created by  Philippe 'BooK' Bruhat 
# Please include the string:  [perl #21575]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21575 >



This is a bug report for perl from book@cpan.org,
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------
[Please enter your report here]

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).

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'};

Now if we change the script by adding a use strict line:

$ cat printstrict.pl
#!/usr/bin/perl
use strict;
my %data = ( foo => 'bar' );
print(
$data{foo});

You'll notice a big difference:

$ perl5.6.1 -MO=Deparse printstrict.pl
Global symbol "$data" requires explicit package name at printstrict.pl line 5.
printstrict.pl had compilation errors.
my(%data) = ('foo', 'bar');
print 'data'->{'foo'};

(same output with 5.8.0 and 5.9.0)

Naturally, everything works as expected when the whole script is
rewritten as :

#!/usr/bin/perl
my %data = ( foo => 'bar' );
print($data{foo});

So it looks like putting a newline between print( and the hash element
breaks the parser.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.6.1:

Configured by buildd at Sat Nov 30 17:45:17 UTC 2002.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.19, archname=i386-linux
    uname='linux cyberhq 2.4.19 #1 smp sun aug 4 11:30:45 pdt 2002 i686 unknown '
    config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20011002 (Debian prerelease)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -ldb -ldl -lm -lc -lcrypt
    perllibs=-ldl -lm -lc -lcrypt
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=true, libperl=libperl.so.5.6.1
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    /home/book/sources/perl
    /home/book/bin/perl
    /usr/local/lib/perl/5.6.1
    /usr/local/share/perl/5.6.1
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.6.1
    /usr/share/perl/5.6.1
    /usr/local/lib/site_perl
    .

---
Environment for perl v5.6.1:
    HOME=/home/book
    LANG=fr_FR@euro
    LANGUAGE (unset)
    LC_ALL=french
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/book/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/games:/usr/local/games:/usr/local/lib/jdk/bin:.
    PERL5LIB=/home/book/sources/perl:/home/book/bin/perl
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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