This approach is unreliable. On my machine the script:
use Data::Dumper;
print Dumper({
1007 => "Hello",
1195 => "World",
});
print Dumper({
1195 => "World",
1007 => "Hello",
});
produces the output:
$VAR1 = {
1195 => 'World',
1007 => 'Hello'
};
$VAR1 = {
1007 => 'Hello',
1195 => 'World'
};
The issue is that Data::Dumper just returns keys in the
order that keys gave it, which returns keys that are in
the same bucket in the insertion order. With a 2 key
hash your odds of hitting this are 1/8. But when the
hashing algorithm works right, a fixed portion of the
keys wind up in a bucket with a neighbour. Therefore
for larger hashes you are virtually guaranteed that the
set of keys alone does not determine what order they
come back in.
If this explanation confuses, then Re (tilly) 4: Flip Flop III - Musical Buckets may
help. |