
depk
New User
Aug 2, 2011, 10:22 PM
Post #5 of 7
(1060 views)
|
|
Re: [BillKSmith] sorting the contents of a file
[In reply to]
|
Can't Post
|
|
I am opening the file and sorting based on the column specified Here is the part of code... open(F1, "C:\\txt.CSV") or die "Cannot open the file"; my @sorted = map {$_->[0]} sort { $a->[$col] <=> $b->[$col] } map {chomp;[$_,split(/,/)]} <F1>; print "$_\n" for @sorted; close (F1); where $col is the column number...... here i'm sorting for a CSV file, I want to know how sorting can be done for a text file or any other type of file. And also, I want to know whether there is any direct sort command in perl like we have in unix "sort -k 2 filename" where it sorts based on the 2nd column
|