如何让一个 Perl 脚本查看另一个 Perl 脚本中的变量? [英] How can I get one Perl script to see variables in another Perl script?
本文介绍了如何让一个 Perl 脚本查看另一个 Perl 脚本中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个越来越大的 Perl 脚本,所以我想把它分解成多个脚本.即,我想取出一些大的哈希声明并将它们放入另一个文件中.如何让原始脚本能够查看和使用现在在另一个脚本中声明的变量?
I have a Perl script that is getting big, so I want to break it out into multiple scripts. namely, I want to take out some large hash declarations and put them into another file. How do I get the original script to be able to see and use the variables that are now being declared in the other script?
这让我发疯,因为我有一段时间没有使用 Perl,而且我一生都无法弄清楚这一点
This is driving me nuts because I haven't used Perl in a while and for the life of me can't figure this out
推荐答案
使用模块:
package Literature;
our %Sidekick = (
Batman => "Robin",
Bert => "Ernie",
Don => "Sancho",
);
1;
例如:
#! /usr/bin/perl
use Literature;
foreach my $name (keys %Literature::Sidekick) {
print "$name => $Literature::Sidekick{$name}\n";
}
输出:
$ ./prog
Bert => Ernie
Batman => Robin
Don => Sancho
这篇关于如何让一个 Perl 脚本查看另一个 Perl 脚本中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文