http://www.perlmonks.org?node_id=768854


in reply to Re^5: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?

Howdy!

You're moving the goalposts.

When you print $h{$_}, you are imposing an order by the sequence of values you assign to $_. The output sequence you are generating is not intrinsic to the hash, but extrinsic.

Your definition of %h is also flawed. You can construct a hash from a list in the manner you do, but there is no assurance that the list you get by saying (%h) will be the same as the list you used to construct the hash.

You don't get a random list when you call keys(). The ordering of the keys is unpredictable at that level. It is deterministic, in that calling keys() repeatedly will give the same list until you add or delete an element from the hash. Then it may come back with a reordered list. The hypothetical "what if perl had" or "what if perl didn't have" questions look like attempts to redefine the question to make it complicated again.

yours,
Michael