
rovf
Veteran
May 18, 2012, 12:29 AM
Post #2 of 9
(1942 views)
|
Re: [cliffyiu] How to sort the following data
[In reply to]
|
Can't Post
|
|
This looks more like a question about an algorithm than about Perl... I could see several approaches, but the basic idea is always to consider an 'item' to sort not being one line, but one group. A straightforward (not necessarily the best) approach would be to build an auxiliary array, where each array holds one group. For efficiency reason (i.e. if you have to sort more than just a few groups), you might consider extracting the number which is used to be sorted, when building the array. For instance, your aux array could look like this: [ [35939758,"John 35939758\nJohn 35941793\nJohn 35943998 ], [11920824,"Amy 11920824\n], ... ] You then sort the auxiliary array according to the extracted numbers, and create from the sorted array the result data.
|