1

我尝试处理以下由get_pool_member_object_status_($pool)

来自http://search.cpan.org/~ltp/BigIP-iControl/lib/BigIP/iControl.pm#get_pool_member_object_status_($pool)

$VAR1 = [
      [
        bless( [
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.141',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.142',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.143',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.144',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' )
               ], 'LocalLB::PoolMember::MemberObjectStatus[]' )
      ]
    ];

我无法弄清楚这应该如何工作。我尝试了 perldsc 的几个示例。那里的示例主要涉及哈希数组。但是上面的数组是......?我什至不知道这是什么类型的数组。有人可以指出我正确的方向吗?

"object_status"->"availability_status"例如, 我如何访问"member"->"address"

谢谢辛巴克。这是我得到的输出Data::Printer:

[
[0] [
    [0] LocalLB::PoolMember::MemberObjectStatus[]  {
        public methods (0)
        private methods (0)
        internals: [
            [0] LocalLB::PoolMember::MemberObjectStatus,
            [1] LocalLB::PoolMember::MemberObjectStatus,
            [2] LocalLB::PoolMember::MemberObjectStatus,
            [3] LocalLB::PoolMember::MemberObjectStatus
        ]
    }
]

]

4

1 回答 1

1

因此,您正在尝试访问, 'availability_status''address'
我没有遍历整个对象,但是使用此代码,我可以打印所需的字段。

#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;


my $obj = [
      [
        bless( [
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.141',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.142',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.143',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' ),
                 bless( {
                          'member' => bless( {
                                             'address' => '192.168.100.144',
                                             'port' => '80'
                                           }, 'Common::IPPortDefinition' ),
                          'object_status' => bless( {
                                                    'availability_status' => 'AVAILABILITY_STATUS_GREEN',
                                                    'status_description' => 'Pool member is available',
                                                    'enabled_status' => 'ENABLED_STATUS_ENABLED'
                                                  }, 'LocalLB::ObjectStatus' )
                        }, 'LocalLB::PoolMember::MemberObjectStatus' )
               ], 'LocalLB::PoolMember::MemberObjectStatus[]' )
      ]
    ];

print Dumper($obj->[0]->[0]->[0]->{member}->{address});
print Dumper($obj->[0]->[0]->[0]->{object_status}->{availability_status});
print Dumper($obj->[0]->[0]->[1]->{member}->{address});
print Dumper($obj->[0]->[0]->[1]->{object_status}->{availability_status});
print Dumper($obj->[0]->[0]->[2]->{member}->{address});
print Dumper($obj->[0]->[0]->[2]->{object_status}->{availability_status});
print Dumper($obj->[0]->[0]->[3]->{member}->{address});
print Dumper($obj->[0]->[0]->[3]->{object_status}->{availability_status});

输出:

$VAR1 = '192.168.100.141';
$VAR1 = 'AVAILABILITY_STATUS_GREEN';
$VAR1 = '192.168.100.142';
$VAR1 = 'AVAILABILITY_STATUS_GREEN';
$VAR1 = '192.168.100.143';
$VAR1 = 'AVAILABILITY_STATUS_GREEN';
$VAR1 = '192.168.100.144';
$VAR1 = 'AVAILABILITY_STATUS_GREEN';

希望这会有所帮助,现在您应该能够使用循环遍历此数据结构。

于 2016-06-22T07:57:45.707 回答