Not true. Of course you can sort a hash. The random part is the order in which the keys get inserted, but if you do
sort(keys %hash)
you'll get the keys in alphabetical order. If you do sort { $a <=> $b } keys %hash;
you'll get the keys in numerical order.
The only thing you can't get from the hash is the order in which things were added
Update: I can't type ... switched can get to can't get in the sentence above, sort of changes the meaning :)
Update: sauoq is correct and I'm completely wrong (not the first time) I wasn't thinking about the fact that sort is simply returning the keys in the order which you ask. The original remains the same. Apologies sweetblood.
Lobster Aliens Are attacking the world! |