|Syntactic Confectionery Delight|
Re^2: hash randomization and keys()by grinder (Bishop)
|on Jul 30, 2007 at 07:09 UTC ( #629495=note: print w/replies, xml )||Need Help??|
The hash seed is changing each time:PERL_HASH_SEED_DEBUG=1 perl -le 1
Remember that a hash is mapping an arbitrary string into one of a finite number of buckets. Hash collisions are common, and so for two keys that hash to the same value, their contents will be found somewhere down in a linked list of values hanging off the bucket.
The orginal attack was that one could concoct a series of keys that kept hashing to the same bucket. The post-5.8.1 hash seed initialises a constant in the hashing algorithm, which makes different buckets get used. But if you're using the same data, they'll follow a different but equivalent bucket usage, and so will appear "in the same order" when you pull them out again. You need something fairly low-level to view the buckets and SVs hanging off each one. I'm not sure off-hand what can be used: Devel::Peek doesn't go far enough.
At another level, there is code in place to detect when single-bucket allocation is occurring, and then the hash is rehashed to break up the list across many buckets. Since your data is insufficiently pathological, you're not seeing the rehashing occurring from run to run.
At least, I think that's what's going on...
• another intruder with the mooring in the heart of the Perl
In Section Seekers of Perl Wisdom