I think I have the right idea but there's some syntax/convention thing I'm messing up, because I get the error "Global symbol %timeHash requires explicit package name".
Code:
foreach $key (sort hashValueDescendingNum (keys(%timeHash))) {
print "\t$key\t\t $timeHash{$key}\n";
}
sub hashValueDescendingNum {
my $hash = shift;
$hash{$b} <=> $hash{$a};
}
Inline
Using a custom sort function the way you are trying to will not work well, because then your sub would need to access the original hash.
Instead you can abstract it further:
The code is not efficient because it passes around the %hash though, references would be better: