我得到了下面的perl错误。
Can't use string ("") as a symbol ref while "strict refs" in use at test173 line 30.粘贴了下面的代码。第30行是open语句。它在open语句中失败。我的脚本中有use strict;和use warnings;。该错误表示什么?如何更改代码以解决此错误。
my $file = 'testdata';
open($data, '<', $file) or die "Could not open '$file'\n";
print "file data id:$data\n";
@iu_data = <$data>;
$totalLineCnt = @iu_data;
print "total line cnt: $totalLineCnt". "\n";发布于 2012-07-05 08:17:06
请确保您之前没有为$data赋值。我可以用三行代码重现你的问题:
use strict;
my $data = '';
open($data, '<', 'test.txt');例如,您可以通过创建一个新的作用域来解决问题:
use strict;
my $data = '';
{
my $data;
open($data, '<', 'test.txt');
close($data);
}或者,您可以在使用$data之前取消定义它:
use strict;
my $data = '';
undef $data;
open($data, '<', 'test.txt');
close($data);等,等…
https://stackoverflow.com/questions/11336528
复制相似问题