Perl学习笔记之文件操作(perl常用函数)一篇读懂

随心笔谈10个月前发布 admin
96 0


#! c:/perl/bin/perl -w
use utf8;
use strict;
use warnings;

my $filename=’test.txt’;
if(open(MYFILE,$filename))
{
my @myfile=<MYFILE>; #如果要读取多行,用此方法,如果只读取一行为:$myfile=<>;
my $count=0; #要读取的行数,初始值为0
printf “I have opened this file: %s\n”, $filename;
while($count < @myfile){ #遍历
print (“$myfile[$count]\n”); #注意此种写法.
$count++;
}
close(MYFILE);
}
else{
print “I can’t open this file!”;
}
exit;

© 版权声明

相关文章