Since you can't know how to sort the totals until they have all been calculated, I think it would be a good idea for you to build an intermediate data structure (an array of hashes would be ideal) containing the name, the two associated values, and the total. Either that, or rearrange your input data into something a little better organized, ie. one set of names that points at both values. Rather than:
%x = ( 'abc' => 2 ) ; %y = ( 'abc' => 3 ) ;
Try something like:
@data = ( { 'name' => 'abc', 'x' => 2, 'y' => 3 }, { 'name' => 'xyz', 'x' => 4, 'y' => 5 } ) ;
I realize this may not be so simple if your data is coming from somewhere else, but keep it in mind nonetheless.
i'm currently running a foreach loop that looks like this:
Er, the one you posted doesn't run. AFAIK, sort keys by %x isn't Perl. Also, your sample data doesn't match your code. I think you'll get better help if you post:
In reply to Re: help with sort by value
by DamnDirtyApe
in thread help with sort by value
by rchou2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |