And to change the sort column, change the expression
$docs{$b}->{freq} <=> $docs{$a}->{freq}
to use whichever column to sort by. Note $b is before $a because you wanted descending sort.
Main Topics
Browse All TopicsI'm doing a computation and that will result in 3 variable (Document name, document value, document term frequency) The values of the computation is in 3 separate variable, so I was thinking of grouping the values into an array or hash so I can sort the result of the computation by the following rules.
The highest document value and the highest term frequency.
here is a sample data
doc1, 0.002, 1
doc2, 0.012, 2
doc3, 0.032, 1
the search Martrix should be like this
doc2, 0.012, 2
doc3, 0.032, 1
doc1, 0.002, 1
How can I create a matrix in perl? or an array of array?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Just found this... I guess I can use this to sort the result
http://search.cpan.org/~dc
You can, it depends really on what you want. The <=> and cmp operators compare 2 values and return -1, 0 or 1. But you can write a sort function that makes it clearer.
So basically comparing the 1st column, if they are not equivalent, return the sort order just based on 1st column, but if they are equivalent, then return sort based on 2nd.
There may be an even more elegant solution to this, but this is how I would do it.
Keep in mind this is sorting on the fly. If you want to maintain a sorted datastructure with many items, you probably should sort them as you store them.
Business Accounts
Answer for Membership
by: mrjoltcolaPosted on 2009-04-05 at 13:09:16ID: 24072777
You can do it in a hash, then use sort on one of the values by providing a sort routine.
Select allOpen in new window