[EMAIL PROTECTED] wrote:
> 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
  Here is one way:

my @MyData = ();
while ( <DATA> ) {
    chomp;
    push(@MyData,$_);
 }

foreach my $MyKey (sort {$a->[3] <=> $b->[3]} map{[$_, split(/:/,$_)]}
@MyData) {
    printf "%-s\n", $MyKey->[0];
 }
 
__DATA__
fred:lucy:24
john:jane:10
frank:mary:5

#output:
frank:mary:5
john:jane:10
fred:lucy:24

Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


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

Reply via email to