以下是一个包P4site.pm的内容
our %regVal = (
'wint' => {
'Bangalore' => {
'regSuffix' => 'reg_run',
'P4PORT' => {
'rd' => '9876',
'pv' => '1991',
},
},
'Noida' => {
'activeRelease' => {
'rd' => {
'43.1' => ['rc011', 'nfm'],
'98.3' => ['rc008', 'nfm'],
'57.3' => ['rc001', 'nfm'],
},
'pv' => {
'43.1' => ['rc011', 'nfm'],
'98.3' => ['rc008', 'nfm'],
'57.3' => ['rc001', 'nfm'],
}
}
我的 Perl 代码是:
use strict;
use warnings;
use FindBin qw($Bin);
use lib "$Bin/modules";
use P4site;
use Data::Dumper;
print Dumper(\%{$P4site::regVal});
foreach my $branches (sort keys %{$P4site::{regVal}})
{
print "$branches is bracnhes\n";
}
为什么
sort keys %{$P4site::{regVal}}
没有给出任何输出?
perl 代码的输出是:
Name "P4site::regVal" used only once: possible typo at allUtilsCopyUserRunMach.pl line 14.
$VAR1 = {};
我期望在运行此 perl 代码后会打印 regVal 哈希的键(在 P4site 中提到)?我如何打印 regVal 哈希的键?
如果变量定义为
our %regVal = (
那你就不能轻率地将
%
改成$
。
print Dumper(\%P4site::regVal);
foreach my $branches (sort keys %P4site::regVal)
{
print "$branches is bracnhes\n";
}