【发布时间】:2019-10-26 09:19:01
【问题描述】:
我有 2 个 perlmodule 文件 (.pm)。 File_A.pm 位于 /some/dir/here/File_A.pm。我有一个位于 /some/other/dir/File_B.pm 的 File_B.pm。
如果 File_A.pm 使用 if(-r '/some/dir/here/File_A.pm' ) 否则它将使用 File_B.pm 中定义的标准哈希作为我的 %machines = ()。
我试过下面的代码
但是,这对我不起作用。
package some::other::dir::File_B;
use strict;
use vars qw(@ISA @EXPORT $VERSION);
use Cwd;
use some::dir::File_A;
use Exporter;
$VERSION = 1.0;
@ISA = qw(Exporter);
@EXPORT =
qw(getMachines printMachines getMachineAttributes printMachineAttributes);
if(-r '/some/dir/here/File_A.pm'){
my %machines = do q{/some/dir/here/File_A.pm};
else{
my %machines = (
"some.fqdn.com" => {
role => ["someRole"],
environment => "test",
location => "USA",
os => "Ubuntu",},
)
}
###################################
#I have getMachines, printMachines, getMachineAtrributes, and
#printMachineAttributes below here in my code
####################################
我希望逻辑使用 File_A.pm 我的 %machines 哈希(如果它是可读的),如果不使用备份我的 %machines 哈希以防 File_A.pm 不知何故变得不可读。
【问题讨论】:
标签: perl hash package perl-module exporter