afox123 发表于 2017-5-17 07:50:58

perl读写文件

#!/usr/bin/perl
my $SRC_FILE="/home/lgg/t.txt";
my $DEST_FILE="/home/lgg/dest.txt";
if (open (SRCFILE ,"<$SRC_FILE"))
{
   open (DESTFILE ,">$DEST_FILE");
   my @reads = <SRCFILE>;
   my $count=$#reads;
   my $curr_index= 0;
   while($curr_index <=$count)
   {
   my $line = $reads[$curr_index];
$line=~s/^\s+|\s+$//g;
if ( nil ne $line && "" ne $line)
{
print DESTFILE "$line\n";
   }
$curr_index++;
   }
   close DESTFILE;
   close SRCFILE;
}
else
{
   print "Source file $SRC_FILE not found!\n";
}
页: [1]
查看完整版本: perl读写文件