我要hases的數組,我傳遞給一個子程序在我的perl腳本參考如何遍歷Perl中對哈希數組的引用?
這是代碼:
sub mySub {
(my $resultref) = @_;
my @list = @$resultref;
print Dumper(@list);
foreach my $result (@list) {
print Dumper($result);
}
}
這是輸出:
$VAR1 = [
{
'portName' => '1.1',
'ips' => [
'192.168.1.242'
],
'switchIp' => '192.168.1.20',
'macs' => [
'00:16:76:9e:63:47'
]
},
{
'portName' => '1.10',
'ips' => [
'192.168.1.119',
'192.168.1.3'
],
'switchIp' => '192.168.1.20',
'macs' => [
'd0:67:e5:f8:7e:7e',
'd0:67:e5:f8:7e:76'
]
},
];
$VAR1 = [
{
'portName' => '1.1',
'ips' => [
'192.168.1.242'
],
'switchIp' => '192.168.1.20',
'macs' => [
'00:16:76:9e:63:47'
]
},
{
'portName' => '1.10',
'ips' => [
'192.168.1.119',
'192.168.1.3'
],
'switchIp' => '192.168.1.20',
'macs' => [
'd0:67:e5:f8:7e:7e',
'd0:67:e5:f8:7e:76'
]
},
];
循環將整個數組放入$ result變量中。我曾嘗試將它作爲@ $ result [0]解除引用,但沒有成功。
我該如何循環這些散列?
謝謝!
謝謝,解釋是非常有幫助和完整 – Joon
@Joon不客氣。 – TLP