【发布时间】:2014-01-21 15:22:58
【问题描述】:
我对这两个文件有疑问: 1)
use strict;
use warnings;
use v5.12;
use externalModule;
my $file = "test.txt";
unless(unlink $file){ # unlink is UNIX equivalent of rm
say "DEBUG: No test.txt persent";
}
unless (open FILE, '>>'.$file) {
die("Unable to create $file");
}
say FILE "This name is $file"; # print newline automatically
unless(externalModule::external_function($file)) {
say "error with external_function";
}
print FILE "end of file\n";
close FILE;
和外部模块(.pm)
use strict;
use warnings;
use v5.12;
package externalModule;
sub external_function {
my $file = $_[0]; # first arguement
say "externalModule line 11: $file";
# create a new file handler
unless (open FILE, '>>'.$file) {
die("Unable to create $file");
}
say FILE "this comes from an external module";
close FILE;
1;
}
1; # return true
现在, 在第一个 perl 脚本第 14 行:
# create a new file handler
unless (open FILE, '>>'.$file) {
die("Unable to create $file");
}
如果有的话
'>'.$file
相反,外部模块打印的字符串不会显示在最终的 test.txt 文件中。
为什么会这样??
亲切的问候
【问题讨论】:
-
见
perldoc perlopentut -
注意:它是一个文件 handle(保存的东西),而不是文件 handler(处理的东西)
标签: perl perl-module