"Steven Massey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
m...
> 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.
>

Hi Steven

This will work. Let us know if you want the code explaining.

Thanks to Ed for his people.

    my @array = qw(
        fred:lucy:24
        john:jane:10
        frank:mary:5
        rupert:cindy:16
    );

    my @sorted = sort {
        (split ':', $a)[-1] <=> (split ':', $b)[-1]
    } @array;

    print "$_\n" foreach @sorted;

Cheers,

Rob




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

Reply via email to