English 中文(简体)
缩略语:阵列
原标题:Perl: array de-reference

我试图说明如何在阵列中贬低价值,但已经到了死端,我曾试图研究这一问题,但需要一些帮助。

• 收集一些数据,从英正统数据库中收集,并试图在结果中搜索,以找到东道国入境的玉米地址。

use strict;
use Data::Dumper;
my @results = $session->get(
   object  => "Infoblox::DNS::Host",
   name    => "test.com.au",
   ipv4addrs   => ".*.",
   view    => "external"
);

使用_->美元的数据结构的高水平Im de-referencing;ipv4addrs 然后使用以下代码对产出进行对比:

foreach (@results) {
    my @search = $_->ipv4addrs;        
         foreach (@search) {
             print Dumper($_) . "
";
    }
}

使用数据印刷以下产出:

$VAR1 = [
      bless( {
                network  =>  111.111.111.0/25 ,
                options  => [],
                dynamic  =>  false ,
                __version  =>  4.2r5-5-68691 ,
                VIEW_FUNCTION  => {
                                     remove  =>  .com.infoblox.perl_api.Infoblox.DHCP.remove_fixed_address ,
                                     search  =>  .com.infoblox.perl_api.Infoblox.DHCP.search_fixed_address ,
                                     add  =>  .com.infoblox.perl_api.Infoblox.DHCP.insert_fixed_address ,
                                     add_using_template  =>  .com.infoblox.perl_api.Infoblox.DHCP.insert_fixed_address_using_template ,
                                     get  =>  .com.infoblox.perl_api.Infoblox.DHCP.get_fixed_address ,
                                     modify  =>  .com.infoblox.perl_api.Infoblox.DHCP.modify_fixed_address 
                                  },
                ipv4addr  =>  111.111.111.111 ,
                match_client  =>  MAC ,
                mac  =>  00:11:00:11:00:11 ,
                disable  =>  false ,
                __type  =>  .com.infoblox.perl_api.Infoblox.DHCP.FixedAddr 
             },  Infoblox::DHCP::FixedAddr  )
    ];

但是,如果我尝试使用_->mac在 for(@searh)坡道内打字,我就错了:

 "Can t call method "mac" on unblessed reference at ./connect_test.pl line nn."

我的编码技能此时失败,任何信息或方向都会受到高度赞赏。

最佳回答

储存在<代码>@search上的每个项目都是阵容。

# If arrayref contains only one     | # If multiple objects expected
# Infoblox::DHCP::FixedAddr object  | # inside @search
                                    |
                                    |
foreach ( @search ) {               | foreach my $item ( @search ) {
                                    | 
    my $obj = shift @$_;            |     foreach my $obj ( @$item ) {
    my $mac = $obj->mac;            |
}                                   |         my $mac = $obj->mac;
                                    |     }
                                    | }
问题回答

阵列的第一个要素是无节制的参考。

$_->[0]->mac

您可直接查阅<代码>->营运人(如上所述)的阵列参考资料中的内容,或将其完全引向一个名单:@list = @{$array_ reference}





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签