We don't bite newbies here... much | |
PerlMonks |
Re: How do I sort a Hash of Hashes?by NetWallah (Canon) |
on Jan 10, 2004 at 05:55 UTC ( [id://320301]=note: print w/replies, xml ) | Need Help?? |
The most straightforward answer is as neuroball has stated: sort { $products{$a}->{"name"} cmp $products{$b}->{"name"} } However.... This has some performance implications in that the hash dereference and comparison get performed many more times than necessary, as sort calls the compare routine each time it compares. This is a lot more then the number of elements to be compared. If the number of elements is large, and you care about performance, you should look into the Schwartzian Transform algorithm, which perfoms the de-reference the minimum number of times. Editor's Note: See, however, this discussion, which reveals that hash dereferences are not usually expensive enough to warrant the power and majesty of a Schwartzian transform...
In Section
Seekers of Perl Wisdom
|
|