濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > perl讀寫文件代碼實(shí)例

perl讀寫文件代碼實(shí)例

熱門標(biāo)簽:智能機(jī)器人電銷神器 電話機(jī)器人哪里有賣 okcc外呼系統(tǒng)怎么調(diào)速度 熱門電銷機(jī)器人 惠州龍門400電話要怎么申請(qǐng) 萬(wàn)利達(dá)百貨商場(chǎng)地圖標(biāo)注 河南虛擬外呼系統(tǒng)公司 外呼電信系統(tǒng) 上海企業(yè)外呼系統(tǒng)

#mode operand create truncate
#read  
#write >  yes yes 
#append >> yes

Case 1: Throw an exception if you cannot open the file:

復(fù)制代碼 代碼如下:

use strict;
use warnings;
 
my $filename = 'data.txt';
open(my $fh, ':encoding(UTF-8)', $filename)
or die "Could not open file '$filename' with the error $!";
 
while (my $row = $fh>) {
chomp $row;
print "$row\n";
}
close($fh);
  

Case 2: Give a warning if you cannot open the file, but keep running:

復(fù)制代碼 代碼如下:

use strict;
use warnings;
 
my $filename = 'data.txt';
if (open(my $fh, ':encoding(UTF-8)', $filename)) {
while (my $row = $fh>) {
chomp $row;
print "$row\n";
}
close($fh);
} else {
warn "Could not open file '$filename' $!";
}
  

Case 3: Read one file into array

復(fù)制代碼 代碼如下:

use strict;
use warnings;
 
my $filename = 'data.txt';
open (FILEIN, "", $filename)
or die "Could not open file '$filename' with the error $!";
my @FileContents = FILEIN>;
for my $l (@FileContents){
print "$l\n";
}
close FILEIN;
  

end

標(biāo)簽:綏化 周口 秦皇島 綿陽(yáng) 合肥 百色 淮安 周口

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《perl讀寫文件代碼實(shí)例》,本文關(guān)鍵詞  perl,讀寫,文件,代碼,實(shí)例,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《perl讀寫文件代碼實(shí)例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于perl讀寫文件代碼實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    措美县| 金华市| 洛隆县| 科尔| 锡林郭勒盟| 永顺县| 郸城县| 虹口区| 财经| 南华县| 延寿县| 都江堰市| 济宁市| 西和县| 新沂市| 临颍县| 扎赉特旗| 永城市| 循化| 融水| 桦南县| 喀喇沁旗| 文成县| 正镶白旗| 博野县| 马公市| 晴隆县| 恩平市| 明光市| 深水埗区| 增城市| 晋州市| 罗平县| 鲁山县| 连南| 屏南县| 本溪市| 吴川市| 潼南县| 昭觉县| 凤庆县|