I have a hash of hashes where the values are all numerical. I can sort fine using the sort command and or to sort the hash values in order first to last, but what if I want to weight the results instead of it just being in order of keys specified? Is there a way to do that?
EDIT: Ok, here's the code...
my @check_order = ["disk_usage","num_dbs","qps_avg"];
my %weights = ( disk_usage => .7,
num_dbs => .4,
qps_avg => .2
);
my @dbs=sort {
($stats{$a}->{$check_order[0]}*$weights{$check_order[0]}) <=>
($stats{$b}->{$check_order[0]}*$weights{$check_order[0]}) or
($stats{$a}->{$check_order[1]}*$weights{$check_order[1]}) <=>
($stats{$b}->{$check_order[1]}*$weights{$check_order[1]}) or
($stats{$a}->{$check_order[2]}*$weights{$check_order[2]}) <=>
($stats{$b}->{$check_order[2]}*$weights{$check_order[2]})
} keys(%stats);