develooper Front page | perl.perl5.porters | Postings from May 2004

[perl #29701] Inconsistencies between 'if/unless' and 'while/until' w.r.t. localised variables

From:
perl @ jagerman . com
Date:
May 19, 2004 01:40
Subject:
[perl #29701] Inconsistencies between 'if/unless' and 'while/until' w.r.t. localised variables
Message ID:
rt-3.0.9-29701-87741.16.8398876872253@perl.org
# New Ticket Created by  perl@jagerman.com 
# Please include the string:  [perl #29701]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29701 >



This is a bug report for perl from perl@jagerman.com,
generated with the help of perlbug 1.35 running under perl v5.9.1.

-----------------------------------------------------------------

I came across an inconsistency yesterday in Perl with respect to a different
between 'if/unless' and 'while/until' with respect to $1 being localised.  The
following example illustrates the problem:

until ("foo" =~ /(foo)/) { }
print "after until: " . ($1 // "<undefined>");
unless ("foo" =~ /(foo)/) { }
print "after unless: " . ($1 // "<undefined>");

The output:

after until: <undefined>
after unless: foo

Though somewhat trivial, this seems inconsistent.  One cannot do:
    if (my $foo) { }
or
    while (my $foo) { }
and then expect to use $foo - it seems the same rules should be followed w.r.t.
scope due to localizing.

What is quite strange is that the behaviour is completely opposite for both -
and thus still different between the two - when using explicitly localised
variables:

$ perl -le '$foo = 3; unless (local $foo = 4) { } print $foo'
3
$ perl -le '$foo = 3; until (local $foo = 4) { } print $foo'
4

The *expected* behaviour is both if/unless and while/until work the same with
respect to scoping.  The above may be identifying two separate bugs, but both
seem to be related inconsistencies.

-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.9.1:

Configured by Gentoo at Tue May  4 11:06:30 PDT 2004.

Summary of my perl5 (revision 5 version 9 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.6.6-rc3-mm1, archname=i686-linux-thread-multi
    uname='linux cytherea.office.gossamer-threads.com 2.6.6-rc3-mm1 #1 fri apr 30 12:39:33 pdt 2004 i686 amd athlon(tm) xp authenticamd gnulinux '
    config_args='-des -Darchname=i686-linux-thread -Dcccdlflags=-fPIC -Dccdlflags=-rdynamic -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-march=athlon-xp -O3 -mmmx -msse -m3dnow -mfpmath=sse -pipe -fomit-frame-pointer -fforce-addr -funroll-loops -frerun-loop-opt -Dusedevel -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Dusethreads -Di_gdbm -Di_db -Di_ndbm'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=athlon-xp -O3 -mmmx -msse -m3dnow -mfpmath=sse -pipe -fomit-frame-pointer -fforce-addr -funroll-loops -frerun-loop-opt',
    cppflags='-DPERL5 -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing'
    ccversion='', gccversion='3.3.3 20040412 (Gentoo Linux 3.3.3-r3, ssp-3.3-7, pie-8.5.3)', 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, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.3.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.3'
  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.9.1:
    /etc/perl
    /usr/lib/perl5/site_perl/5.9.1/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.9.1
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.9.1/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.9.1
    /usr/lib/perl5/vendor_perl/5.8.3/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.3
    /usr/lib/perl5/vendor_perl/5.8.2
    /usr/lib/perl5/vendor_perl/5.8.1/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.9.1/i686-linux-thread-multi
    /usr/lib/perl5/5.9.1
    /usr/local/lib/site_perl
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.1
    .

---
Environment for perl v5.9.1:
    HOME=/home/jagerman
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin/wrappers:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.3:/opt/ati/bin:/opt/Acrobat5:/opt/f-prot:/usr/X11R6/bin:/opt/sun-jdk-1.4.2.04/bin:/opt/sun-jdk-1.4.2.04/jre/bin:/opt/sun-jdk-1.4.2.04/jre/javaws:/usr/qt/3/bin:/usr/kde/3.2/bin:/usr/games/bin:/opt/quake3:/opt/vmware/bin:/usr/X11R6/bin:/home/jagerman/bin:/opt/perl/perl-5.00404/bin:/opt/perl/perl-5.005/bin:/opt/perl/perl-5.00503/bin:/opt/perl/perl-5.6.1/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About