如何打印在另一个文件中定义的散列元素?如何打印在另一个文件中定义的散列元素?
file1.pl:
#!/usr/bin/perl
use strict;
use warnings;
our %hash =
("Quarter" , 25,
"Dime" , 10,
"Nickel" , 5);
file2.pl:
#!/usr/bin/perl
use strict;
use warnings;
require "file1.pl"
foreach (sort keys %hash){
print "$hash{$_}\n";
}
输出:
Global symbol "%hash" requires explicit package name.
Global symbol "%hash" requires explicit package name.
请帮助
以供将来参考,请选择您的代码,然后按Ctrl-K或工具栏,以使你的代码看起来正确的相应按钮。 – ikegami 2013-03-27 07:30:13
(忽略我的投票关闭。我在关闭投票提到的职位已经插入了一个错误,因为昨天他们的回答。) – ikegami 2013-03-27 07:37:33
http://stackoverflow.com/questions/4543934/how-to-share-export-a- global-variable-between-two-different-perl-scripts这个问题看起来类似于你所需要的。 – 2013-03-27 08:28:36