尝试打开文件句柄以写入文本,但脚本始终失败并出现错误:
Can't use an undefined value as a symbol reference at C:/Users/USER/Documents/script.pl line 207, <GEN1> line 20001.
at C:/Users/USER/Documents/script.pl line 207, <GEN1> line 20001.
示例代码:
my $fileo = 'C:\Users\USER\Documents\report.txt';
# Open output file handle
my $fho = IO::File->new($fileo, 'w');
say $fho "THIS FILE: $fileo";
$fho->close();
我已经检查了
Perldocs
和 MetaCPAN
关于模块 IO:File
但我看不出语法有任何问题。
有什么想法吗?
打开文件时出错。
my $fho = IO::File->new( $fileo, 'w' )
or die( "Can't create `$fileo`: $!\n" );
额外的层没有用处。
open( my $fho, '>', $fileo )
or die( "Can't create `$fileo`: $!\n" );