Undoubtedly not the best way of doing this, but here's one stab at it.
This assumes you have your data stored in an array as a single string,
rather than having an array of array pointers.
my @array = ('fred:lucy:24', 'john:jane:10', 'frank:mary:5');
@array = sort { my @a_vals = split (':', $a);
my @b_vals = split (':', $b);
$a_vals[2] <=> $b_vals[2]; } @array;
foreach my $string(@array) { print "$string\n"; }
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 29, 2003 11:50 AM
> To: [EMAIL PROTECTED]
> Subject: sorting thoughts
>
>
> Hi
>
> just about to embark on a sorting routine, and I thought
> before I spend
> ages(at my ability) I would see what thoughts you guys have on this.
>
> 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
>
> Thanks - here's hoping..
> Steve
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]