#! c:/perl/bin/perl -w
use utf8;
use strict;
use warnings;
#! 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;
© 版权声明
文章版权归作者所有,未经允许请勿转载。