---
title: "perl读写文件"
author: "luogen33"
date: "2012-05-23T10:03:54Z"
tags: []
categories: ["编程语言"]
slug: "perl"
draft: false
lastmod: "2012-05-23T10:03:11Z"
id: 1538361
url: "https://luogen33.iteye.com/blog/1538361"
---

#!/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;
	 $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";
}