最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年05月08日 11:21:11   投稿:junjie  
這篇文章主要介紹了perl讀寫文件代碼實(shí)例,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下

#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

相關(guān)文章

最新評論

加查县| 东兰县| 五大连池市| 新安县| 宁蒗| 五莲县| 迁安市| 蒙阴县| 大连市| 霍城县| 江达县| 庆阳市| 三亚市| 长顺县| 综艺| 阳谷县| 赤峰市| 沧州市| 鹤岗市| 界首市| 连城县| 南安市| 兴化市| 东宁县| 顺义区| 精河县| 双鸭山市| 溧水县| 容城县| 永寿县| 宁津县| 云霄县| 和硕县| 合水县| 赣州市| 油尖旺区| 长春市| 海安县| 冀州市| 威远县| 莫力|