Here is a shot without checks and assumes the data will be numeric(sorting on 
column 3):
#!perl -w

use strict;
my @MD = ();

while ( <DATA> ) {
    chomp;
    next if ( /^\s*$/ );
    push (@MD, $_);
 }

foreach my $MyData (sort {$a->[3] <=> $b->[3]} 
                    map{ [$_, split(/\s+/,$_) ] } 
                    @MD ) {
    printf "%s\n",
               $MyData->[0];
 }
 
__DATA__
Abc 12.8 8 "left" 1 15.7
Def  13.8 9 "top" 0 19.7
gef  14.8 9 "left" 0 19.7
Dgf  12.3 9 "right" 4 99.6
cef  16.8 4 "right" 0 89.7
baf  32.8 7 "bottom" 5 79.8
efg  16.8 5 "right" 0 56.7
etg  12.8 2 "left" 7 34.7

Output:
etg  12.8 2 "left" 7 34.7
cef  16.8 4 "right" 0 89.7
efg  16.8 5 "right" 0 56.7
baf  32.8 7 "bottom" 5 79.8
Abc 12.8 8 "left" 1 15.7
Def  13.8 9 "top" 0 19.7
Dgf  12.3 9 "right" 4 99.6
gef  14.8 9 "left" 0 19.7


      Any questions and/or problems, please let me know.

     Thanks.

Wags ;)

-----Original Message-----
From: Boon Chong Ang [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 29, 2004 16:38
To: [EMAIL PROTECTED]
Subject: sort


Hi,

I want to write a perl script to do something like this

 

Abc 12.8 8 "left" 1 15.7

Def  13.8 9 "top" 0 19.7

gef  14.8 9 "left" 0 19.7

Dgf  12.3 9 "right" 4 99.6

cef  16.8 4 "right" 0 89.7

baf  32.8 7 "bottom" 5 79.8

efg  16.8 5 "right" 0 56.7

etg  12.8 2 "left" 7 34.7

 

 

Just say I want to sort the row based on the value on fifth or third column, any 
advice how to do so?

 

 

Thank you & best regards,

ABC

 



**********************************************************
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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to