develooper Front page | perl.perl5.porters | Postings from April 2001

[ID 20010427.002] Problem with "each %"-construct (BUG) 5.005,5.6.0, 5.6.1

Thread Next
From:
tiadm
Date:
April 27, 2001 03:42
Subject:
[ID 20010427.002] Problem with "each %"-construct (BUG) 5.005,5.6.0, 5.6.1
Message ID:
20010427104214.13366.qmail@tollt.ti.telenor.net

This is a bug report for perl from obh@nextra.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.


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

I believe there is an bug in the "each %{...}" construct and I have 
enclosed a program that exposes this bug. The bug exist in perl 5.003, 
5.004, 5.005, 5.6.0, 5.6.1.

#!/local/net/perl/bin/perl

$NAME{all}->{1} = A;
$NAME{all}->{2} = B;
$NAME{all}->{3} = C;
$NAME{all}->{4} = D;
$NAME{all}->{5} = E;
$NAME{all}->{6} = F;
$NAME{all}->{7} = G;


foreach (1, 2)
{
  #my @re = keys %{$NAME{all}};

  my $i = 0;
  my ($re, $name);
  while (($re, $name) = each %{$NAME{all}}) {
    print "$re --> $name\n";
    last if $i++ == 3;
  }
  print "RE=$re NAME=$name i=$i\n";
}

exit(0);

When I run the program above, I get

7 --> G
1 --> A
2 --> B
3 --> C
RE=3 NAME=C i=4
4 --> D
5 --> E
6 --> F
RE= NAME= i=3

I believe I should have got:

7 --> G
1 --> A
2 --> B
3 --> C
RE=3 NAME=C i=4
7 --> G
1 --> A
2 --> B
3 --> C
RE=3 NAME=C i=4

If I remove the comment before "my @re = keys %{$NAME{all}};", I get the
expected result.

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

Configured by obh at Fri Apr 27 12:01:28 MEST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos tollt.ti.telenor.net 5.8 generic_108528-06 sun4u sparc '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.6'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    /local/net/lib/perl5/sun4-solaris
    /local/net/lib/perl5
    /local/net/lib/perl5/site_perl/5.005/sun4-solaris
    /local/net/lib/perl5/site_perl/5.005
    /local/net/lib/perl5/mrtg2
    /local/net/perl/lib/5.6.1/sun4-solaris
    /local/net/perl/lib/5.6.1
    /local/net/perl/lib/site_perl/5.6.1/sun4-solaris
    /local/net/perl/lib/site_perl/5.6.1
    /local/net/perl/lib/site_perl
    .

---
Environment for perl v5.6.1:
    HOME=/local/ti/home/tiadm
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=iso_8859_1
    LD_LIBRARY_PATH=/local/X11/lib:
    LOGDIR (unset)
    PATH=/local/net/bin:/local/gnu/bin:/local/bin:/local/net/slipstat/minutes/bin:/local/ti/bin:/local/gnu/bin:/local/bin:/home/o/obh/bin:/local/net/bin:/local/net/netflow/bin:/local/net/rocs/bin:/local/bin:/local/gnu/bin:/usr/ucb:/usr/bin:/usr/sbin:/usr/ccs/bin:/local/X11/bin:/usr/openwin/bin:/local/sbin:/usr/dt/bin:/usr/ucb
    PERL5LIB=/local/net/lib/perl5:/local/net/lib/perl5/site_perl/5.005:/local/net/lib/perl5/mrtg2
    PERL_BADLANG (unset)
    SHELL=/local/gnu/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