May 18, 2012, 12:29 AM
Post #2 of 9
This looks more like a question about an algorithm than about Perl...
Re: [cliffyiu] How to sort the following data
[In reply to]
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 ],
You then sort the auxiliary array according to the extracted numbers, and create from the sorted array the result data.