Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print for @{ my $x }; doesn't report "Can't use an undefined value..." #11270

Closed
p5pRT opened this issue Apr 21, 2011 · 8 comments
Closed

print for @{ my $x }; doesn't report "Can't use an undefined value..." #11270

p5pRT opened this issue Apr 21, 2011 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 21, 2011

Migrated from rt.perl.org#89024 (status was 'rejected')

Searchable as RT89024$

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

From contact@johnbokma.com

Created by contact@johnbokma.com

perl -e 'use strict; use warnings; print for @​{ my $x }'
Can't use an undefined value as an ARRAY reference at -e line 1.

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

perl -e 'use strict; use warnings; print for @​{ my $x }'

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

The behaviour in 5.10.0 seems unexpected. When I posted this bug
to comp.lang.perl.misc, C.DeRykus reports the same issue with
5.12.2.

Perl Info

Flags:
     category=core
     severity=high

Site configuration information for perl 5.10.0:

Configured by Debian Project at Thu Oct  1 22:36:47 UTC 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
   Platform:
     osname=linux, osvers=2.6.24-23-server, 
archname=x86_64-linux-gnu-thread-multi
     uname='linux crested 2.6.24-23-server #1 smp wed apr 1 22:14:30 utc 
2009 x86_64 gnulinux '
     config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN 
-Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr 
-Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 
-Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 
-Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local 
-Dsitelib=/usr/local/share/perl/5.10.0 
-Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 
-Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 
-Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl 
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio 
-Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib 
-Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=define, usemultiplicity=define
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN 
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
     optimize='-O2 -g',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing 
-pipe -I/usr/local/include'
     ccversion='', gccversion='4.4.1', gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -L/usr/local/lib'
     libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
     libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
     perllibs=-ldl -lm -lpthread -lc -lcrypt
     libc=/lib/libc-2.10.1.so, so=so, useshrplib=true, 
libperl=libperl.so.5.10.0
     gnulibc_version='2.10.1'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
     cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches:



@INC for perl 5.10.0:
     /home/john/.local-perl//x86_64-linux-gnu-thread-multi
     /home/john/.local-perl/
     /etc/perl
     /usr/local/lib/perl/5.10.0
     /usr/local/share/perl/5.10.0
     /usr/lib/perl5
     /usr/share/perl5
     /usr/lib/perl/5.10
     /usr/share/perl/5.10
     /usr/local/lib/site_perl
     .


Environment for perl 5.10.0:
     HOME=/home/john
     LANG=en_US.UTF-8
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
     PERL5LIB=/home/john/.local-perl/
     PERL_BADLANG (unset)
     SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

From @iabyn

On Wed, Apr 20, 2011 at 06​:21​:14PM -0700, John Bokma wrote​:

perl -e 'use strict; use warnings; print for @​{ my $x }'
Can't use an undefined value as an ARRAY reference at -e line 1.

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

perl -e 'use strict; use warnings; print for @​{ my $x }'

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

The behaviour in 5.10.0 seems unexpected. When I posted this bug
to comp.lang.perl.misc, C.DeRykus reports the same issue with
5.12.2.

Bisect shows the error went away with this commit​:

commit a62b51b
Author​: Shinya Hayakawa <hayakawa@​livedoor.jp>
Date​: Tue May 25 09​:06​:06 2004 +0900

  Re​: my $x->{foo} doesn't work
  Message-Id​: <200405250006.06387.hayakawa@​livedoor.jp>
 
  Allow autovivification of (my $x)->{foo}
 
  p4raw-id​: //depot/perl@​22874

So it looks like it was deliberate.

--
"There's something wrong with our bloody ships today, Chatfield."
  -- Admiral Beatty at the Battle of Jutland, 31st May 1916.

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

From contact@johnbokma.com

On Thu Apr 21 03​:36​:11 2011, davem wrote​:

On Wed, Apr 20, 2011 at 06​:21​:14PM -0700, John Bokma wrote​:

perl -e 'use strict; use warnings; print for @​{ my $x }'
Can't use an undefined value as an ARRAY reference at -e line 1.

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

perl -e 'use strict; use warnings; print for @​{ my $x }'

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

The behaviour in 5.10.0 seems unexpected. When I posted this bug
to comp.lang.perl.misc, C.DeRykus reports the same issue with
5.12.2.

Bisect shows the error went away with this commit​:

commit a62b51b
Author​: Shinya Hayakawa <hayakawa@​livedoor.jp>
Date​: Tue May 25 09​:06​:06 2004 +0900

Re&#8203;: my $x\->\{foo\} doesn't work
Message\-Id&#8203;:  \<200405250006\.06387\.hayakawa@&#8203;livedoor\.jp>

Allow autovivification of \(my $x\)\->\{foo\}

p4raw\-id&#8203;: //depot/perl@&#8203;22874

So it looks like it was deliberate.

Thanks Dave.

What I don't understand, but that has a lot to do with not knowing a
thing about the Perl internals is that​:

perl -e 'use strict; use warnings; my $x; for ( @​$x) { print }'
perl -e 'use strict; use warnings; my $x; print for @​$x'

but​:

perl -e 'use strict; use warnings; my $x; print while @​$x'
Can't use an undefined value as an ARRAY reference at -e line 1.
perl -e 'use strict; use warnings; my $x; while ( @​$x ) { print }'
Can't use an undefined value as an ARRAY reference at -e line 1.

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

From @ikegami

On Wed, Apr 20, 2011 at 9​:21 PM, John Bokma <perlbug-followup@​perl.org>wrote​:

# New Ticket Created by John Bokma
# Please include the string​: [perl #89024]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=89024 >

This is a bug report for perl from contact@​johnbokma.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]
perl -e 'use strict; use warnings; print for @​{ my $x }'
Can't use an undefined value as an ARRAY reference at -e line 1.

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

perl -e 'use strict; use warnings; print for @​{ my $x }'

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

The behaviour in 5.10.0 seems unexpected. When I posted this bug
to comp.lang.perl.misc, C.DeRykus reports the same issue with
5.12.2.

Dereferences of undefined scalars in lvalue context result in
autovivification, meaning an variable of the appropriate type is created,
and a reference to it is placed in a scalar. This is documented in perlref.

Just like the argument list of sub calls, The list over which foreach
iterates is evaluated in lvalue context as required by foreach's aliasing
property.

Autovivification often creates unexpected behaviour, but it is intended
behaviour. Knowing about autovivification, I wouldn't expect any of the
following to issue warnings​:

$ perl -we'my $x; @​$x = qw( a b c );'

$ perl -we'@​{ my $x } = qw( a b c );'

$ perl -we'my $x; for (@​$x) {}'

$ perl -we'for (@​{ my $x }) {}'

$

@p5pRT
Copy link
Author

p5pRT commented Apr 21, 2011

From contact@johnbokma.com

On Thu Apr 21 11​:11​:03 2011, ikegami@​adaelis.com wrote​:

behaviour. Knowing about autovivification, I wouldn't expect any of
the
following to issue warnings​:

$ perl -we'my $x; @​$x = qw( a b c );'

$ perl -we'@​{ my $x } = qw( a b c );'

$ perl -we'my $x; for (@​$x) {}'

$ perl -we'for (@​{ my $x }) {}'

To me this is too much magic. Is this on the list of changes between 5.8
to 5.10 or is this just something that crept in and now has become a
'feature'?

@p5pRT
Copy link
Author

p5pRT commented Apr 22, 2011

From contact@johnbokma.com

Eric,

I have given it some more thought. I do think that this makes Perl more
magic than before, and have the feeling that this can cause hard to
track bugs. But on the other hand I do see the logic of it.

Thanks for the explanation,
John

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2011

@cpansprout - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant