sort of thing.foreach my $key ( sort { $hash{$a} cmp $hash{$b} } keys %hash ) { # do something useful }
I will need to use a named sort function, specified at runtime, but something like this will not work:
Because %hash is not necessarily scoped in my_sorter()foreach my $key ( sort my_sorter keys %hash ) { # do something useful } ... ... sub my_sorter { return $hash{$a} cmp $hash{$b}; }
In my situation, it will be nearly impossible to have the hash being sorted in the proper scope directly.
What i realy want to do is pass anonymous sort subroutines into the function that needs to sort the hash, but i just dont see how to make this work properly. The hash itself will always be out of scope.
Note that this is a simplification of the real problem, the sorting by values problem is only part of the situation, but its the only part thats giving me trouble.
So i guess the real issue is: How do i sort by values without an inlined sort?
Thanks much - beating my head
In reply to Sort by value - new twist by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |