在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' )
]发布于 2016-04-07 15:29:56
您所转储的是一个数组,而不是哈希。你需要给Dumper打电话,让我们给你适当的帮助
而且,由于这是一个受祝福对象的结构,所以应该使用它们的方法来访问信息,而不是通过“后门”直接破坏数据结构。不幸的是,GuestStackInfo和NetDnsConfigInfo是VMware类,而不是标准的Perl类型之一,所以我不能建议哪些方法调用可能是合适的
这里有一些笔记
$VAR1引用的结构是一个包含GuestStackInfo对象的单元素数组。GuestStackInfo对象包含一个NetIpRouteConfigInfo对象和一个NetDnsConfigInfo对象。我假设您对后者感兴趣,因为您说的是“值是ip附件”,而最近的散列键是ipAddress中的NetDnsConfigInfo对象。ipAddress元素引用IP类地址字符串数组。若要访问此数组,请编写
my $addresses = $VAR1->[0]{dnsConfig}{ipAddress};然后把它们全部打印出来
print "$_\n" for @$addresses;但是请注意我最初的评论--你应该使用方法调用,而不是像这样在数据结构中穿插。有那些类的文档吗?
https://stackoverflow.com/questions/36479565
复制相似问题