主题:问一个文件输出的问题?
我编了一个打开文件,然后输出文件内容的小程序,结果输出总是不对,哪位能帮忙看一下? “myfile.dat”文件和程序在同一个目录下面,而且里面有内容,输出的结果总是为空。
#! /usr/bin/perl
$filename = "myfile.dat";
open (FILE, "$filename") || print "Can not open myfile.dat!\n";
@myflie = <FILE>;
close FILE;
print " myfile is: ", @myfile;
foreach $line (@myfile)
{
print $line;
}
# now print the number of lines in @myfile
print "\n lines: ", $#myfile+(1-$[);
# now print the number of chars in @myfile
foreach $line (@myfile)
{
$chars += length($line);
}
print "\n characters: ", $chars;
------------------------------------
[color=FF0000]输出结果如下:[/color]
myfile is:
lines: 0
characters:
#! /usr/bin/perl
$filename = "myfile.dat";
open (FILE, "$filename") || print "Can not open myfile.dat!\n";
@myflie = <FILE>;
close FILE;
print " myfile is: ", @myfile;
foreach $line (@myfile)
{
print $line;
}
# now print the number of lines in @myfile
print "\n lines: ", $#myfile+(1-$[);
# now print the number of chars in @myfile
foreach $line (@myfile)
{
$chars += length($line);
}
print "\n characters: ", $chars;
------------------------------------
[color=FF0000]输出结果如下:[/color]
myfile is:
lines: 0
characters: