The ordering of elements in a hash is based on the hash function. The hash function processes a key and determines where in the hash that key should be placed. For any given key, the hash function must always return the same result. A good hash function will tend to keep keys spread out in the hash; if all the keys end up in the same place in the hash, then you lose the benefit of having a hash.
So, there is an "order" to the elements in the hash, but the order is not intended to be useful to the programmer, and keys may be reordered when the size of the hash changes. | [reply] |
Oh, it is ordered in some way, just not any way that is
obvious to the casual user. The sort order is indicative
of how perl is modelling the hash internally. Yes you'll
see the same order each time you run the script, but that
may well not be true if you were to run it on another
operating system or a different version of Perl.
All in all, it's best to assume that the ordering
is random.
--
<http://www.dave.org.uk>
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
| [reply] |