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

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

perl @ jagerman . com
May 19, 2004 01:40
[perl #29701] Inconsistencies between 'if/unless' and 'while/until' w.r.t. localised variables
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #29701]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
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) { }
    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

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

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.

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:
    osname=linux, osvers=2.6.6-rc3-mm1, archname=i686-linux-thread-multi
    uname='linux 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
    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/, so=so, useshrplib=false, libperl=libperl.a
  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:

Environment for perl v5.9.1:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About