in reply to Re: Sort by value - new twist
in thread Sort by value - new twist
Regarding all options you propose: you need to handle that $a and $b is a package global if you want to have your sort routines elsewhere. IMHO, the easiest way to handle this is simply to pass them along in the function call. I.e. for option 1:
my $sorter = \&my_sorter; foreach my $key (sort { $sorter->(\%hash, $a, $b) } keys %hash) { # do something useful } sub my_sorter { my ($hashref, $a, $b) = @_; return $hashref->{$a} cmp $hashref->{$b}; }
You can do it by using caller and symbolic links, but I don't see any real benefit by that.
ihb
Read argumentation in its context!
|
|---|