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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.