Perl: the Markov chain saw | |
PerlMonks |
Re^7: What makes an array sorted and a hash unsorted?by herveus (Prior) |
on Jun 03, 2009 at 18:33 UTC ( [id://768109]=note: print w/replies, xml ) | Need Help?? |
Howdy!
You are missing the point. In general, a Perl hash with a given set of keys will produce them in a consistent order when you call keys(). Calling keys() makes the set of keys into a list. That list is inherently ordered, but it's not the hash. Now, add or delete elements from the hash. There is no assurance that the list returned by keys() will be in the same order. In fact, insertions can change the order of keys that existed before. The set of keys in a hash has no deterministic fixed order. Change the insertion order and the keys come out in a different order. Consider the following: which produced the following output:
If there was an intrinsic sequence, why does adding "foo" to hash cause "x" to suddenly appear much earlier in the list produced by keys()? Why are the lists with all eight keys not the same? If the sequence were intrinsic, one would not expect either of those outcomes.
yours, Michael
In Section
Meditations
|
|