rchou2 has asked for the wisdom of the Perl Monks concerning the following question:
The output file looks like:foreach $Name(sort keys %x) { $total_x= $x{$Name}; $total_y= $y($Name}; if ($total_y> 0) { $total_value= $total_x/$total_y; printf INTFILE "%-50s %10.3f %15.2f %10.3f %10.5f\n", $Name, $ +total_x, $total_y, $total_value; }
I want to sort the output such that everything is sorted in descending order based on the total_value, so the output should be:Name x y total_value abc 3 4 5 xyz 2 1 8
The problem is that the computation of total_value is done inside the loop, so I was wondering if there was anyway around it. I need to keep the foreach loop to get the values of x and y. Thanks.Name x y total_value xyz 2 1 8 abc 3 4 5
-r
Edit by dws to add <code> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting by Value
by Abigail-II (Bishop) on Jul 19, 2002 at 15:46 UTC | |
|
Re: Sorting by Value
by simeon2000 (Monk) on Jul 19, 2002 at 15:57 UTC |