my $myFile = "akshay.txt";
open my $IO, "<", $myFile or die ("Cant open $myFile because $!");
print "File $myFile has opened successfully\n";
my $line = <$myFile>;
print $line;
close $IO;
错误:
File akshay.txt has **opened successfully**
readline() on **unopened filehandle** at akshay.pl line 29.
Use of uninitialized value $line in print at akshay.pl line 30.
为什么会出现这种矛盾? 在Windows和ActivePerl上运行。
答案 0 :(得分:3)
您必须使用文件句柄来阅读它:
<hr class="abc"></hr>
.abc{
width: 100px;
height: 100px;
background: red;
}
答案 1 :(得分:0)
更改此行:
my $line = <$myFile>;
到
my $line = <$IO>;
您正在使用filename变量来读取文件内容。使用文件句柄。
答案 2 :(得分:0)
您使用了filename变量而不是filehandle变量,固定代码应如下所示:
my $myFile = "akshay.txt";
open my $IO, "<", $myFile or die("Cant open $myFile because $!");
print "File $myFile has opened successfully\n";
my $line = <$IO>;
print $line;
close $IO;