4

I'm working with the Perl API of an Infoblox appliance (doc: https://ipam.illinois.edu/api/doc/)

I have the following code:

...

my $specificRecord = $recordResults[0];

say $specificRecord->name();

foreach ($specificRecord->ipv4addrs())
{
    say $_;
}

$specificRecord contains an Infoblox::DNS::Host record object.

My problem comes when I'm iterating over ipv4addrs(). According to the documentation and the perl debugger, ipv4addrs() returns an ARRAY containing IPs or DHCP::FixedAddr objects.

In my case, if I debug my program and "x" $specificRecord->ipv4addrs() as well as $_, I get the same result:

DB<1> b 70

DB<2> c
Results: 1
aaaa9999test.justice
main::(testScript2.pl:70):          foreach ($specificRecord->ipv4addrs())
main::(testScript2.pl:71):          {

DB<2> x $specificRecord->ipv4addrs();
0  ARRAY(0x64e9e3c)
   0  '8.8.8.8'
   1  '8.8.4.4'

DB<3> n
main::(testScript2.pl:72):              say $_;

DB<3> x $_;
0  ARRAY(0x64e9e3c)
   0  '8.8.8.8'
   1  '8.8.4.4'

Here is a relevant portion of "x" of the Infoblox::DNS::Host object:

DB<2> x $specificRecord;
0  Infoblox::DNS::Host=HASH(0x8b3eacc)
   '__object_id__' => 'dns.host$._default.justice.aaaa9999test'
   'aliases' => ARRAY(0x8b3e9fc)
        empty array
   'configure_for_dns' => 'true'
   'disable' => 'false'
   'ipv4addrs' => ARRAY(0x64e9e3c)
      0  '8.8.8.8'
      1  '8.8.4.4'
   'ipv6addrs' => ARRAY(0x8aa1bac)
        empty array
   'name' => 'aaaa9999test.justice'
   ...

I can't tell what I'm doing wrong and why foreach doesn't work with the $_ variable. I tried assigning ipv4addrs() to an array and then foreaching over that, to no avail.

1 Answer 1

8

It's returning an array reference. Try dereferencing it:

foreach ( @{ $specificRecord->ipv4addrs() } )
Sign up to request clarification or add additional context in comments.

2 Comments

@gparent it would be even more confusing, if it dereferenced the array ref for you.
Oh I'm sure, it's just that this sort of problem seems more immediately obvious in other programming languages. Maybe I'm wrong, I'm definitely inexperienced with Perl and I like learning more about it, but that's my opinion so far. When I said stupidity I didn't want to imply that the language was wrong, but that I spent a lot of time on something silly :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.