On Wed, 29 Jan 2003 16:50:03 +0000, Steven Massey wrote:

> I have an array, each line contains fields seperated by ":"
> I want to sort the array numerically ascending by the last field.
> 
>  my thoughts are to split fields into seperate arrays, go through the last
> array in a comparing process, moving each row index in the original array
> to reflect the sort. ( I found this hard to explain)
> 
> Do any of you some tips as to how to approach this ??
> 
> eg
> contents of array1
> fred:lucy:24
> john:jane:10
> frank:mary:5
> 
> so I want to end up with
> frank:mary:5
> john:jane:10
> fred:lucy:24

Here's a solution exploiting the Sort::Fields module from CPAN. It has the
main advantage to be very readable and easy to program without errors. (Of
course for the price of a little speed penalty).

use Sort::Fields;

print fieldsort ':', ['3n'], @array;


Greetings,
Janek



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to