原始檔:
#!/usr/bin/perl
# file: read-file.pl
use strict;       /啟動嚴格語法檢查
use IO::File;   
/找入 IO::Fil e模組
my $file=shift;  /將檔名 透過 shift () 出命令列,以供輸入,並存入 $file
my $fh =IO::File->new($file)||die "Read file Error Try again\n";
                     /透過 IO::File->new() 開啟檔案,並傳回 一個檔案代號 存入$fh
while(my $line=<$fh>){ /只要能從檔案讀取-條件為真
print $line;       /將讀取的文字一行印出螢幕
}

原始檔:
#!/usr/bin/perl
# file: count_line.pl
use strict;       /啟動嚴格語法檢查
use IO::File;    /找入 IO::File模組
my $file=shift;  /將檔名 透過 shift () 出命令列,以供輸入,並存入 $file
my $counter=0;/初始化 $counter 為零
my $fh =IO::File->new($file) || die "無法開啟 $file: $!\n";
while (my $line =$fh->getline) {
 $counter++;
}
STDOUT->print "共計有 $counter 列\n";

arrow
arrow
    全站熱搜

    hweily 發表在 痞客邦 留言(0) 人氣()