in reply to Re^9: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?
the hash must traverse the internal data structures in some order to produce the list, but that sequence is explicitly undefined. That is the essence of being unordered.
I've been watching from the sidelines and for the most part, this seems like a prime example of what killed the Pedants' Conferencethey died arguing about whether the ' should be before or after the sbut I've always enjoyed a good freindly debate, so here goes nothing :)
I would say that for all hash implementations, including Perl's current, (and all previous) implementations, they do have an "intrisic ordering". That ordering is a definable and concrete function of 2 factors:
 The hashing algorithm.
 The bucket size at the point of traversal.
And given knowledge of algorithm (use the source), and the current bucket size, (see the second element of scalar %hash), the ordering is knowable; therefore definable; therefore defined by the implementation(s).
However, I agree with the earlier statementI've lost track of who made it (first)that there is a significant difference between "order(inged)" and "sort(inged)".
And the answer to the OP question is:
Whilst the iteration order of arrays is, (for most (all?) languages), unspecified, it is defined, (by convention), to be the same as the natural ordering of its integer indexes; whereas, the iteration order of hashes, (also unspecified), is defined, (as a matter of practicality), to be the simplest or most efficient, (which are often the same thing), order of traversal of the datastructures underlying the implementation.
As hash implementations differ, the ordering differs with implementation; whereas the natural ordering of integer indexes does not.
QED.


Replies are listed 'Best First'.  

Re^11: What makes an array sorted and a hash unsorted? (nit)
by tye (Sage) on Jun 05, 2009 at 15:29 UTC  
by BrowserUk (Pope) on Jun 05, 2009 at 17:31 UTC 