in reply to Sorting by Value

That's strange. You calculate $total_value as $total_x/$total_y, then print out $total_x, $total_y, $total_value, and get 2, 1, 8 and 3, 4, 5. Your Perl must be really, really broken. Also, your format for printf has 5 %'s, but you only have 4 parameters.

Anyway, the answer is the preprocess the data.

map {printf INFILE "%-50s %10.3f %10.3f %10.5f\n" => @$_} sort { $a -> [3] <=> $b -> [3]} map {[$_, $x {$_}, $y {$_}, $x {$_} / $y {$_}]} grep { $y {$_} > 0} keys %x;

Abigail