in reply to Hash sorting

You need to consider what you really want to do with your data. A hash is a bag that holds a bunch of data that you access using a key. There is no 'order' to the data. In fact, what order it may have will change as data is added and removed from the bag.

If you want fast access to a chunk of data given a key, use a hash. If you want to preserve the order of a list of stuff, use an array. If you want to do both use a tied hash (Tie::IxHash as suggested by Zaxo). Note though that a tied hash does neither job as well as the built in structures.

Most often though all you need is to generate a sorted list of keys when you need them using something like sort keys %hash. If what you want is to sort by the values and don't care about the keys you can sort values %hash. But really, any general advice is likely to be overtaken by your actual application. To get solid advice, provide a small sample of the sort of data and the code that you are using. Mention too how much data there is and how often you may need to access the data in sorted order. All those things influence the choices that may be made.


DWIM is Perl's answer to Gödel