Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Net::DNS::Resolver and nameservers

by henzen (Acolyte)
on May 13, 2011 at 14:22 UTC ( #904680=perlquestion: print w/replies, xml ) Need Help??

henzen has asked for the wisdom of the Perl Monks concerning the following question:


I'm slow today for some reason - maybe too little coffee, and would appreciate some wisdom.

Net::DNS::Resolver->new(nameservers => [qw(1 2 3)]...

That's the usual usage, ie, hard coding the nameserver IPs. I want to use a variable such as @nameservers (or even the scalar $nameservers):

Net::DNS::Resolver->new(nameservers => [@nameservers]...

This works, but it only queries the first nameserver. The remainder are ignored (so it fails if the first NS is dead).

I cannot hard-code as $ns = qw(ip1 ip2 ip3 ip4), since the IPs are sourced from another variable and qw() doesn't interpolate (so I cannot do $ns = qw($ip1 $ip2 $ip3 $ip4))...

I just need to programmatically pass several nameserver IPs to Net::DNS::Resolver.

Any pointers to alleviate my dumbness would be appreciated. Thanks

Replies are listed 'Best First'.
Re: Net::DNS::Resolver and nameservers
by gam3 (Curate) on May 13, 2011 at 14:38 UTC
    The code Net::DNS::Resolver->new(nameservers => [qw(1 2 3)]; and the code
    @nslist = qw(1 2 3); Net::DNS::Resolver->new(nameservers => [@nslist];
    are the same, so I think the problem with only the first DNS server being queried is a problem with the Net::DNS::Resolver package or the underlieing library. You might randomize the list of nameservers and reload them in a different order if a request fails.
    -- gam3
    A picture is worth a thousand words, but takes 200K.
      Thanks for the quick response. It looks like this was bad data ('', '', '...').

      If was dead, it hit '' and soiled itself...
Re: Net::DNS::Resolver and nameservers
by jellisii2 (Hermit) on May 13, 2011 at 15:01 UTC
    The documentation states that it takes an arrayref. Have you tried to use Net::DNS::Resolver->new(nameservers => [\@nameservers] ...
      Na, that makes it fail every time. Problem solved though, so thanks anyway.

      [\@foo] is an AoA, not an arrayref. Update: Well, it is an arrayref of sorts, but not an arrayref reference to an array (better? ;-b) of scalars containing strings. :-)


        but not an arrayref of scalars. :-)

        An arrayref is a reference to an array is always a reference to an array, no mater what the array contains, and yes, arrayrefs , like all refs, are scalars -- tricky :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://904680]
Approved by Corion
Front-paged by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-03-07 16:19 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (122 votes). Check out past polls.