Gossamer Forum
Home : General : Perl Programming :

sort file

Quote Reply
sort file
please help,


I'm a newbie so please be patient.

I have a file, say file.txt.

The contents of the file are:

z
x
h
w
a



how do i open this file and sort it, and output it into a different file, say sorted.txt?


The code I've tried doesn't work:

$file="file.txt";
open FILE, $file or die "cannt open $stuff for read:$!";

while(<FILE>){
@INFO = $_;
$out="sorted.txt";
open OUT, ">>$out" or die "cannot open $out for write :$!";
foreach $letter(@INFO){
$sorted=$sorted+$letter;
}
print "$sorted";
print OUT "$sorted";

}




please can someone tell me what i need to do?

what would the correct code be?

Any help greatly appreciated....
Subject Author Views Date
Thread sort file 0069 4564 Aug 6, 2003, 5:19 AM
Post Re: [0069] sort file
tie571 4442 Aug 12, 2003, 12:52 PM
Post Re: [0069] sort file
Panther 4412 Aug 13, 2003, 3:02 PM