我正在编写一个perl
脚本 ( myscript.pl
),我想按以下顺序从各个模块加载一些环境变量:
- 默认设置在
defaultSettings.pm
同一目录中myscript.pl
- (可选)
userSettings.pm
用户可以选择的其他地方的用户设置 - (可选)
localSettings.pm
当前工作目录中的本地设置
我已经解决了我的第一个和最后一个项目符号,但没有成功解决第二个项目。
myscript.pl
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
# defaultSettings always present in same directory as myscript.pl
use defaultSettings;
# localSettings sometimes present (in current working directory)
eval
{
require localSettings;
localSettings->import();
};
print "Some variable is: ",$someVariable;
exit
defaultSettings.pm
package defaultSettings;
use strict;
use warnings;
use Exporter;
use vars qw($VERSION @ISA @EXPORT);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw($someVariable
);
our $someVariable="default settings";
1;
localSettings.pm
package localSettings;
use strict;
use warnings;
use Exporter;
use vars qw($VERSION @ISA @EXPORT);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw($someVariable
);
our $someVariable="local settings";
1;
我知道我可以使用
use lib "/home/foo/bar/";
use userSettings;
中myscript.pl
,但我想避免让用户编辑myscript.pl
- 主要希望/目标是让用户编辑除 myscript.pl
.
我对完成相同想法的其他工作流程持开放态度:)