【发布时间】:2010-09-16 10:56:42
【问题描述】:
我有两个脚本和两个 conf 文件(实际上也是 perl 脚本):
conf1.pl
@some_array = ({name =>"orange", deny = > "yes"},
{name =>"apple", deny = > "no"});
conf2.pl
@some_array = ({name =>"male", deny = > "yes"},
{name =>"female", deny = > "no"});
脚本.pl
#!/usr/bin/perl -w
use strict;
our %deny = ();
call_another_script.pl_somehow_with_param conf1.pl
call_another_script.pl_somehow_with_param conf2.pl
foreach my $key (%deny) {
print $deny{$key},"\n";
}
另一个脚本.pl
#!/usr/bin/perl -w
my $conf_file = shift;
do $conf_file;
foreach my $item (@some_array) {
print $item->{name},"\n";
if (defined $deny) {
$deny{$item{name}}++ if $item{deny} eq "yes";
}
}
我想用 script.pl 中的 conf 文件名调用 another_script.pl,这样 %deny 将在 another_script.pl 中可见。而且我不想使用 Perl 模块,我想将脚本放在单独的文件中。 例如
./another_script.pl conf2.pl
和
./脚本
【问题讨论】:
-
"我想做某事,但我明确不想使用 Perl 的特性来做这件事。但我不想解释为什么我要强加这样一个任意的约束。”