`
luogen33
  • 浏览: 80649 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

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";
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics