That's pretty much what you've been doing, except you're also switching keys and values. I don't see a real reason for doing that, and it complicates your code (since values are not guaranteed to be unique, you have to maintain a list of keys for each), so I'd advise against that.
I was told that by switching the keys and values, it will improve performance during the sort operation because if I sort the values, I have to do two hash lookups for every comparison operation performed by the sort function. If I sort the keys, then I don't.
Therefore, if I really want to sort on the hash values, it would make sense to create a new temporary hash in which the values and keys are swapped, and then sort that new array on its keys (which are the values of the original hash), rather than the values. Is that incorrect?
For example, wouldn't this:
sort { $data_hash{$a} <=> $data_hash{$b} } keys(%data_hash)
be slower than this:
sort { $a <=> $b } keys(%reordered_data_hash)
Where %reordered_data_hash is %data_hash with the values swapped with the keys?
In reply to Re^2: sorting hash of array of hashes by value
by Special_K
in thread sorting hash of array of hashes by value
by Special_K
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |