在 blessed hash 中寻找一个值
Looking of a value in blessed hash
我是 Perl 的初学者,我正在尝试从 à blessed hash 中获取 à 值。
值是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' )
]
无论你转储什么是一个数组,而不是散列。您需要显示对 Dumper
的调用,以便我们正确地帮助您
此外,由于这是受祝福对象的结构,你应该使用他们的方法来访问信息,而不是按照"back door" 直接搞乱数据结构。不幸的是 GuestStackInfo
和 NetDnsConfigInfo
是 VMware 类 而不是标准的 Perl 类型之一,所以我无法建议哪些方法调用可能是合适的
这里有一些笔记
$VAR1
引用的结构是一个包含GuestStackInfo
对象的单元素数组
GuestStackInfo
对象包含一个NetIpRouteConfigInfo
对象和一个NetDnsConfigInfo
对象。我假设你对后者感兴趣,正如你所说的 "The value is ip adresses",最近的散列键是 NetDnsConfigInfo
对象
中的 ipAddress
]
ipAddress
元素是对 数组 IP 地址类字符串的引用
要访问此数组,您需要编写
my $addresses = $VAR1->[0]{dnsConfig}{ipAddress};
然后将它们全部打印出来,使用
print "$_\n" for @$addresses;
但是请注意我最初的评论——您应该使用方法调用,而不是像这样在数据结构周围闲逛。这些 类?
有任何文档吗?
我是 Perl 的初学者,我正在尝试从 à blessed hash 中获取 à 值。
值是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' )
]
无论你转储什么是一个数组,而不是散列。您需要显示对 Dumper
的调用,以便我们正确地帮助您
此外,由于这是受祝福对象的结构,你应该使用他们的方法来访问信息,而不是按照"back door" 直接搞乱数据结构。不幸的是 GuestStackInfo
和 NetDnsConfigInfo
是 VMware 类 而不是标准的 Perl 类型之一,所以我无法建议哪些方法调用可能是合适的
这里有一些笔记
$VAR1
引用的结构是一个包含GuestStackInfo
对象的单元素数组
中的GuestStackInfo
对象包含一个NetIpRouteConfigInfo
对象和一个NetDnsConfigInfo
对象。我假设你对后者感兴趣,正如你所说的 "The value is ip adresses",最近的散列键是NetDnsConfigInfo
对象ipAddress
]ipAddress
元素是对 数组 IP 地址类字符串的引用
要访问此数组,您需要编写
my $addresses = $VAR1->[0]{dnsConfig}{ipAddress};
然后将它们全部打印出来,使用
print "$_\n" for @$addresses;
但是请注意我最初的评论——您应该使用方法调用,而不是像这样在数据结构周围闲逛。这些 类?
有任何文档吗?