【发布时间】:2015-04-21 04:14:47
【问题描述】:
我尝试将两个文件句柄初始化为 NULL,然后在我的程序中使用它。
这是我的代码:
my $fh1 = " ";
my $fh2 = " ";
open($fh1, ">", $fname1);
open($fh2, ">", $fname2);
print $fh1 "HI this is fh1";
执行后,我的文件包含以下内容:
fname1 为空
fname2 包含
Hi this is fh1
错在哪里?
为什么 fname1 是空的,而 fname2 包含一个字符串,即使我没有在 fh2 中插入任何字符串?
【问题讨论】:
-
你用
use strict ; use warnings;试过这个吗?它在公开调用中抛出错误。 -
当我运行你的代码时,我得到这个:
syntax error at fh.pl line 3, near ", >" syntax error at fh.pl line 4, near ", >" Execution of fh.pl aborted due to compilation errors. -
它们是文件句柄
标签: perl file filehandler