Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Deterministic or keys in random order

by almut (Canon)
on May 14, 2008 at 13:42 UTC ( #686511=note: print w/replies, xml ) Need Help??


in reply to Deterministic or keys in random order

If you're specifically referring to "Since Perl 5.8.1 the ordering is different even between different runs of Perl...", I think the "different runs of Perl" is meant to be taken literally, i.e. executing the perl binary. I.e. when dumping the HASH_SEED value, you should in fact get different values each time (unless perl has been built with -DUSE_HASH_SEED_EXPLICIT — see perlrun):

$ PERL_HASH_SEED_DEBUG=1 perl -e1 HASH_SEED = 12018612040932336001 $ PERL_HASH_SEED_DEBUG=1 perl -e1 HASH_SEED = 4459772231957961225 ...

That being said, I still always do get the same ordering every time I do keys %hash ...   So, I'd be interested in an explanation just as much you seem to be :)

Update:  here's some test code:

#!/usr/bin/perl use Test::More; plan tests => 1; my %hash = ( "Zero","0","One","1","Two","2", "Three", "3", "Four", "4", "Five", "5", "Six", "6", ); print "$ENV{PERL_INVOCATION_COUNT}: "; # note: test string has been determined experimentally # (i.e. it might differ with your Perl) ok(join(' ', keys %hash) eq 'Five Four Three Zero Two Six One', q{same + ordering}); if (++$ENV{PERL_INVOCATION_COUNT} < 100 ) { exec $0; }

(prints 100 times "ok ..." with my Perl — despite different hash seed values)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://686511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-12-01 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?