天天看點

Learning Perl 學習筆記

1.檔案讀寫與指令行參數

#!/usr/bin/perl

use strict;

if (@ARGV < 2){

    die  "USAGE: perl $0 inputfile outfile\n";

}

my ($infile) = @ARGV[0];

my ($outfile) = @ARGV[1];

open my $infile_fh,'', "$infile" || die("Can't open the file!");

open my $outfile_fh, '>>', "$outfile"|| die("Can't open the file!");

while(<$infile_fh>){

    #chomp;

    print $outfile_fh  $_;

close($outfile_fh);

close($infile_fh);

本文轉自 pgmia 51CTO部落格,原文連結:http://blog.51cto.com/heyiyi/1596188