hmmmm.....dammit can you even sort hashes...? lol thanks anyway :-) | [reply] |
Hashes have no order. You can't "sort a hash." It's like a big canvas bag filled with all of the key-value pairs. Every time you look, somebody may have shaken the bag.
Arrays have order. You can sort one array and collect the sorted version in another array. It's like a rope upon which all of the elements are tied at various points.
When you say "sort a hash," you really mean, collect the keys or collect some part of the values, and generate a sorted array of those. That is, search through the bag and tie each item onto a rope, until all of the items in the bag are ALSO on the rope.
Often, the first thing you do with this sorted array is to query the hash again, using the sorted array as an ordering guide. That is, following the knots on the rope to visit all of the items in the bag.
I hope the metaphors help.
-- [ e d @ h a l l e y . c c ]
| [reply] |