对文件的每一行字符串进行排序并输出到另一个文件,perl源码如下:
#!/usr/bin/perl -w
open(MYFILE,"myfile.txt")||die "Can't open the file: myfile.txt.";
open(NEWFILE,">new.txt")||die "Can't open the file: newfile.txt.";
while(<MYFILE>)
{
$line=<MYFILE>;
#chomp $line;
@output=(@output,$line);
}
#foreach $item (@output)
{
print NEWFILE sort{$a cmp $b;}@output;
}
close(NEWFILE);
close(MYFILE);
By cursorkey, please reserve all words in the note when you want to copy!