我在我的代碼中使用了兩個哈希值。一,數組推送的問題
Dumper \%userJobCount
$VAR1 = {
'hina' => 2,
'maccetta' => 1,
'vineethk' => 1,
'jpriyank' => 27,
'sanchars' => 1,
'kamran' => 8,
'wilt' => 7,
'sakir' => 5,
'rjernigan' => 8,
'emichael' => 1,
'ranjith' => 8,
'wgutknec' => 7,
'danchuy' => 1,
'saurabh4' => 1,
'chengc' => 9,
'revathi' => 2,
'zumach' => 7,
'hual' => 7,
'lkashyap' => 2,
'raviteja' => 17,
'bsheetal' => 4,
'horgan' => 2,
'tongz' => 6,
'demat' => 1,
'matthew6' => 14,
'alward' => 1,
'adalton' => 1,
'sydneyw' => 5,
'yashodhc' => 1,
'makam' => 1,
'surajs' => 9,
'radish' => 2,
'sudiptac' => 2,
'adityak' => 4,
'dodgson' => 4,
'sudipp' => 6,
'zaw' => 1,
'umeshr' => 23,
'zukas' => 6
};
和
%userJobSubtest = (
name => '',
username => '',
rc => PASS,
notes => ''
);
下面的代碼,我使用它們:
foreach my $key (keys %userJobCount) {
if($userJobCount{$key} > $jobLimit) {
%userJobSubtest = (
name => $key,
username => $key,
rc => WARN,
notes => ''
);
#print Dumper \%userJobSubtest;
push(@{$rtn{subtests}}, \%userJobSubtest);
}
}
print Dumper %rtn;
我將只顯示測驗從總輸出鍵值:
$VAR6 = [
{
'rc' => 3,
'notes' => '',
'name' => 'umeshr',
'username' => 'umeshr'
},
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0],
$VAR6->[0]
];
在代碼中,這部分被註釋掉了:
#print Dumper \%userJobSubtest;
當我運行它,它有其他鍵,其值大於$ jobLimit以上(= 5) 沒有人有一個想法,什麼是與推腳麻的價值?爲什麼當我推動的應該不是真正的價值時,我會得到重複的條目?
PS - 如果將散列和數組的引用傳遞給'Dumper',則會獲得更好的結果。例如,'print Dumper%rtn;'應該是'print Dumper \%rtn;'。在這種情況下,打印Dumper $ rtn {subtests};'會更好。 – ikegami