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

[perl #55952] Iteration order of hash keys doesn't appear random

Thread Next
Jonathan Sailor
June 17, 2008 15:52
[perl #55952] Iteration order of hash keys doesn't appear random
Message ID:
# New Ticket Created by  Jonathan Sailor 
# Please include the string:  [perl #55952]
# 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.8.8.

[Please enter your report here]

It doesn't seem that the iteration order of hash keys is random. On 5.8.8, I
created a hash with a bunch of key/value pairs, and they are always returned by
the hash's iterator in the same order. I'm not sure if the apparent
lack-of-randomness if actually evidence of a problem or not.


    jsailor@gentoo ~ $ cat 
    #!/usr/bin/perl -l
    map { $foo{"key$_"} = "val$_"  } 1 .. 10;
    map { print "$_ => $foo{$_}"   } keys %foo;
    jsailor@gentoo ~ $ for ((i=0; i<10; i++)); do
                        PERL_HASH_SEED_DEBUG=1 perl | md5sum
                       done | sort | uniq -c
    HASH_SEED = 4030767996
    HASH_SEED = 4231742271
    HASH_SEED = 2242964373
    HASH_SEED = 1223985970
    HASH_SEED = 3159642496
    HASH_SEED = 3233708610
    HASH_SEED = 1197677821
    HASH_SEED = 3042627731
    HASH_SEED = 3316032634
    HASH_SEED = 3720177465
         10 b9610c6717785a4f9e26c9913d1bbb06  -
    jsailor@gentoo ~ $ 

This report if for 10 particular keys inserted in a particular order on a
particular build of Perl, as returned by keys, but the order is just as
constant (for me) for:

 - a few different other sets of keys
 - iteration with each
 - Perl on Debian 5.8.8-7etch3, Perl on OSX 10.4


[Please do not change anything below this line]
Site configuration information for perl v5.8.8:

Configured by Gentoo at Mon Nov 19 16:17:34 EST 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
    osname=linux, osvers=2.6.19-gentoo-r5+bsdreiser2_1, archname=i686-linux-thread-multi
    uname='linux 2.6.19-gentoo-r5+bsdreiser2_1 #4 wed sep 26 23:23:37 edt 2007 i686 amd athlon(tm) xp 2800+ authenticamd gnulinux '
    config_args='-des -Darchname=i686-linux-thread -Dcccdlflags=-fPIC -Dccdlflags=-rdynamic -Dcc=i686-pc-linux-gnu-gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-march=athlon-xp -O2 -fomit-frame-pointer -pipe -Duselargefiles -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dinstallman1dir=/usr/share/man/man1 -Dinstallman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dinc_version_list=5.8.0 5.8.0/i686-linux-thread-multi 5.8.2 5.8.2/i686-linux-thread-multi 5.8.4 5.8.4/i686-linux-thread-multi 5.8.5 5.8.5/i686-linux-thread-multi 5.8.6 5.8.6/i686-linux-thread-multi 5.8.7 5.8.7/i686-linux-thread-multi  -Dcf_by=Gentoo -Ud_csh -Dusenm -Dusethreads -Di_ndbm -Di_gdbm -Di_db'
    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=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='i686-pc-linux-gnu-gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=athlon-xp -O2 -fomit-frame-pointer -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)', 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='i686-pc-linux-gnu-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.8.8:

Environment for perl v5.8.8:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About