Could try something like:
#!perl -w
my @MyData = ();
#
# Loading some data
#
push(@MyData , sprintf "%-s\t%-s\t%-s\t%-s\t%-s\t", 'a', 'b','c', 'd','e');
push(@MyData , sprintf "%-s\t%-s\t%-s\t%-s\t%-s\t", 'b', 'd','d', 'e','f');
push(@MyData , sprintf "%-s\t%-s\t%-s\t%-s\t%-s\t", 'c', 'e','e', 'f','g');

printf "before Sorted Data:\n";

foreach (@MyData ) {
   printf "%-s\n", $_;
 }

printf "Sorted Data by 3rd field- descending\n";

foreach my $MyKey (sort {$b->[1] cmp $a->[1]} map { [$_, (split(/\t/, $_))[2] ]} 
@MyData ) {
   printf "%-s\n", $MyKey->[0];
 }      
^--------- Script ends here


Output:
before Sorted Data:
a       b       c       d       e
b       d       d       e       f
c       e       e       f       g
Sorted Data by 3rd field- descending
c       e       e       f       g
b       d       d       e       f
a       b       c       d       e

One way.

Wags ;)
-----Original Message-----
From: Bryan R Harris [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 04, 2002 07:49
To: [EMAIL PROTECTED]
Subject: sort by field




I'm very much a beginner, I guess, the perldoc page on sort doesn't make
much sense to me.

I've got a tab-delimited file read into an array, now I want to sort it on
the contents of column 3.  Could someone point me in the right direction?

TIA.

- Bryan



-- 
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]

Reply via email to