读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 2.7节 笔记
#!/usr/bin/perl
use strict;
use warnings;
open IN_FILE, "<in_file.txt" or die("Could not open in_file.txt");
open OUT_FILE, ">out_file.txt" or die("Could not create out_file.txt");
my $line;
while (1) {
$line = <IN_FILE>;
if (not defined($line)) {
last;
}
print OUT_FILE $line;
}
close(IN_FILE);
close(OUT_FILE);
运行结果:
[root@localhost perl_practice]# cat in_file.txt
hello, world!
[root@localhost perl_practice]# ./copy.pl
[root@localhost perl_practice]# cat out_file.txt
hello, world!
[root@localhost perl_practice]#