develooper Front page | perl.perl5.porters | Postings from June 2002

[ID 20020626.011] wantarray() causes clobbering of unrelated varsoutside the sub

Thread Next
From:
Tassilo von Parseval
Date:
June 26, 2002 11:08
Subject:
[ID 20020626.011] wantarray() causes clobbering of unrelated varsoutside the sub
Message ID:
5.8.0_850_1025113891@ethan

This is a bug report for perl from tassilo.parseval@post.rwth-aachen.de,
generated with the help of perlbug 1.34 running under perl v5.8.0.


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

The following code produces unexplicable behaviour. It can probably be pinned
down to wantarray(), but obviously other factors are playing a role as well
(notably keys()):


#! /usr/bin/perl

use strict;
use warnings;

my %tmp_hash = ( first => 'A', second => 'B' );

foreach my $aaa ( keys %tmp_hash ) {
    print "$aaa --> $tmp_hash{ $aaa }\n";
}

print "First loop:\n";
for my $bbb ( keys %tmp_hash ) {
    print "key1: $bbb\n";
    my ($jjj) = mysub();
    print "key2: $bbb\n";
}

print "Second loop:\n";
my @arr = keys %tmp_hash;
foreach my $bbb ( @arr ) {
    print "key3: $bbb\n";
    my ( $jjj ) = mysub();
    print "key4: $bbb\n";
}

sub mysub {
    my $text = 'select * from employee';
    my $val;
    if ( wantarray and $text =~ /^update/ ) {
        $text;
    }
}

Output:
-------
first --> A
second --> B
First loop:
key1: first
key2: first
Use of uninitialized value in concatenation (.) or string at test.pl line 14.
key1:
key2: select * from employee
Second loop:
key3: first
key4: first
key3: second
key4: second
--------

The warning of unitialized value is spurious here. Furthermore, the second
iteration through the First-Loop-foreach goes terribly wrong. Calling mysub()
in list context changes the content of the lexical $bbb. Interestingly enough,
this does not happen in the second loop that iterates over a copy of keys() and
not over the keys directly.

According to Slaven Rezic, this bug occurs beginning with 5.00503 whereas it
works fine with perl5.00404. I personally observed the faulty behaviour in
5.8.0rc2 and 5.6.1.

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

Configured by root at Mon Jun 24 08:29:49 CEST 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18, archname=i686-linux
    uname='linux ethan 2.4.18 #1 tue feb 26 09:52:36 cet 2002 i686 unknown '
    config_args='-e -Dprefix=/usr/opt'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20011006 (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, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.5'
  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.8.0:
    /usr/opt/lib/perl5/5.8.0/i686-linux
    /usr/opt/lib/perl5/5.8.0
    /usr/opt/lib/perl5/site_perl/5.8.0/i686-linux
    /usr/opt/lib/perl5/site_perl/5.8.0
    /usr/opt/lib/perl5/site_perl
    .

---
Environment for perl v5.8.0:
    HOME=/home/ethan
    LANG=C
    LANGUAGE (unset)
    LC_CTYPE=de_DE@euro
    LD_LIBRARY_PATH=:/usr/local/j2sdk1.4.0/jre/lib/i386:/usr/local/pwlib/lib
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/jdk1.3.1/bin:.
    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