perl读取文件
发布时间:2020-12-16 00:16:14 所属栏目:大数据 来源:网络整理
导读:? 1)文件读取的3中方法 ? 按行读,存入标量 while (FILE) { print; } 按行读,存入数组 @array = FILE; 读入整个文件 ,存入标量 $string = do { local $/; FILE; }; ? 2)读文件实例 open (EP,"/etc/passwd"); while (EP) { chomp; print "I saw $_ in the
?
1)文件读取的3中方法
?
按行读,存入标量
while (<FILE>) { print; }
按行读,存入数组
@array = <FILE>;
读入整个文件 ,存入标量
$string = do { local $/; <FILE>; };
?
2)读文件实例
open (EP,"/etc/passwd");
while (<EP>) { chomp; print "I saw $_ in the password file!n"; }
?
3)读写文件实例
open(IN,$a) || die "cannot open $a for reading: $!";
open(OUT,">$b") || die "cannot create $b: $!"; while (<IN>) { # read a line from file $a into $_ print OUT $_; # print that line to file $b } close(IN) || die "can't close $a: $!"; close(OUT) || die "can't close $b: $!"; ? ? 来自:http://yixf.name/2011/04/26/perl%E8%AF%BB%E5%8F%96%E6%96%87%E4%BB%B6%E4%B8%89%E6%B3%95/? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |