我是Perl中的一个初学者,我正试图从有趣的哈希值中获得值。
价值是ip地址,我试过没有成功
print $vm->guest->ipStack->dnsConfig->ipAddress;
print $vm->guest->ipStack{dnsConfig}{ipAddress};
$VAR1 = [
bless( {
"ipRouteConfig" => bless( {
"ipRoute" => [
bless( {
"gateway" => bless( {
"device" => 0,
"ipAddress" => "10.*******"
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "0.0.0.0",
"prefixLength" => 0
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"network" => "1***********",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"prefixLength" => 23
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 32,
"network" => "10**************",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 32,
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "1***********5"
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 4,
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "224.0.0.0"
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "255.255.255.255",
"prefixLength" => 32
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 64,
"network" => "fe80::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 128,
"network" => "fe80::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 8,
"network" => "ff00::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' )
]
}, 'NetIpRouteConfigInfo' ),
"dnsConfig" => bless( {
"dhcp" => 0,
"searchDomain" => [
"france"
],
"hostName" => "HOST",
"ipAddress" => [
"10.60****",
"10.6*****",
"10.8*****"
],
"domainName" => "france"
}, 'NetDnsConfigInfo' )
}, 'GuestStackInfo' )
]
答案 0 :(得分:3)
无论你转储什么都是数组,而不是哈希。您需要显示对Dumper
的来电,以便我们为您提供正确的帮助
此外,由于这是一个受祝福的对象的结构, 你应该使用他们的方法来访问信息 ,而不是去"后门&#34 ;并直接搞乱数据结构。遗憾的是,GuestStackInfo
和NetDnsConfigInfo
是VMware类,而不是标准Perl类型之一,因此我无法建议可能适合的方法调用
以下是一些注意事项
$VAR1
引用的结构是包含GuestStackInfo
对象的单元素数组
GuestStackInfo
对象包含NetIpRouteConfigInfo
个对象和NetDnsConfigInfo
个对象。我假设您对后者感兴趣,因为您说"值为ip地址" ,ipAddress
对象中最近的哈希键为NetDnsConfigInfo
ipAddress
元素是对类似IP地址字符串的数组的引用
要访问此数组,您需要编写
my $addresses = $VAR1->[0]{dnsConfig}{ipAddress};
然后将它们全部打印出来,使用
print "$_\n" for @$addresses;
但请注意我最初的评论 - 您应该使用方法调用而不是像这样探索数据结构。这些课程有没有文件?