Skip Menu |
 
Report information
Id: 63752
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: kennethk [at] cpan.org
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: medium
Type: notabug
Perl Version: 5.8.8
Fixed In:
  • 5.10.0
  • 5.8.9



Subject: Inconsistent scoping for while .. redo
Date: Mon, 9 Mar 2009 15:09:23 -0600
To: perlbug [...] perl.org
From: Kenneth Kroenlein <kennethk [...] cpan.org>
This is a bug report for perl from kennethk@cpan.org, generated with the help of perlbug 1.35 running under perl v5.8.8. #!/usr/bin/perl # This displays scoping inconsistencies between various # versions of perl. Specifically, under several Linux # builds of v5.8.8, $i becomes undefined after the redo and # the script outputs '2'. # Those are: v5.8.8 built for i386-linux-thread-multi # v5.8.8 built for i486-linux-gnu-thread-multi # v5.8.8 built for x86_64-linux-gnu-thread-multi # For other builds, $i maintains its value and the script # outputs '210'. # Those are: v5.10.0 built for x86_64-linux-gnu-thread-multi # v5.8.8 built for MSWin32-x86-multi-thread # v5.8.9 built for MSWin32-x86-multi-thread # There is a discussion at: # http://www.perlmonks.org/?node_id=749322 use strict; use warnings; my $j = 2; while ( my $i = $j ) { print $i if defined $i; last unless $i--; redo; } --- Flags: category=core severity=medium --- Site configuration information for perl v5.8.8: Configured by Debian Project at Wed Jan 14 22:49:45 UTC 2009. Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.24-16-server, archname=x86_64-linux-gnu-thread-multi uname='linux yellow 2.6.24-16-server #1 smp thu apr 10 13:15:38 utc 2008 x86_64 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -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 -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef 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 -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.2.3 (Ubuntu 4.2.3-2ubuntu7)', 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 libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8 gnulibc_version='2.7' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: --- @INC for perl v5.8.8: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . --- Environment for perl v5.8.8: HOME=/home/kennethk LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH=/opt/sun/sunstudio12/lib/amd64:/opt/sun/sunstudio12/rtlibs/amd64:/opt/intel/fce/10.1.015/lib:/usr/local/lib LOGDIR (unset) PATH=/opt/sun/sunstudio12/bin:/opt/intel/fce/10.1.015/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/u01/app/oracle/product/11.1.0/client_1/bin PERL_BADLANG (unset) SHELL=/bin/bash
Download (untitled) / with headers
text/plain 1.9k
On Mon Mar 09 14:09:46 2009, kennethk@cpan.org wrote: Show quoted text
> This is a bug report for perl from kennethk@cpan.org, > generated with the help of perlbug 1.35 running under perl v5.8.8. > > #!/usr/bin/perl > # This displays scoping inconsistencies between various > # versions of perl. Specifically, under several Linux > # builds of v5.8.8, $i becomes undefined after the redo and > # the script outputs '2'. > # Those are: v5.8.8 built for i386-linux-thread-multi > # v5.8.8 built for i486-linux-gnu-thread-multi > # v5.8.8 built for x86_64-linux-gnu-thread-multi > # For other builds, $i maintains its value and the script > # outputs '210'. > # Those are: v5.10.0 built for x86_64-linux-gnu-thread-multi > # v5.8.8 built for MSWin32-x86-multi-thread > # v5.8.9 built for MSWin32-x86-multi-thread > # There is a discussion at: > # http://www.perlmonks.org/?node_id=749322 > use strict; > use warnings; > > my $j = 2; > while ( my $i = $j ) { > print $i if defined $i; > last unless $i--; > redo; > } > ---
Hello, Thank you for your bug report. A binary search reveals: http://public.activestate.com/cgi-bin/perlbrowse/p/24412 Change 24412 by davem@davem-splatty on 2005/05/07 12:57:06 while (my $x ...) { ...; redo } shouldn't undef $x. In the presence of 'my' in the conditional of a while(), until(), or for(;;) loop, add an extra scope to the body so that redo doesn't undef the lexical This is an intended change of behaviour (a bugfix) so I'm marking this as resolved, notabug. If you want code that behaves correctly on all versions of perl then you should add an extra scope and declare my $i in it. That is: #!/usr/bin/perl use strict; use warnings; my $j = 2; { my $i; while ( $i = $j ) { print $i if defined $i; last unless $i--; redo; } } (The only reason why your code is printing 210 on 'v5.8.8 built for MSWin32-x86-multi-thread ' is because it not a stock perl. (read: patches were applied to it.)) Kind regards, Bram


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org