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

This seems like such a simple module yet I cannot get it to work. I am running this with Perl 5.10 on Cygwin. Here is my code:
#!/usr/bin/perl -w use strict; use Net::Nslookup; my $name=nslookup(domain=>"yahoo.com"); print("name=$name\n");
The result is just 'name='. There is no error so '$name' must be a defined variable but contains a null string.

There were no errors when I installed the module via MCPAN. When I turn debug on all I get is:

Performing 'A' lookup on `yahoo.com' at ....

I don't see how I can screw this up but obviously I am doing something wrong. Can someone help me with this? TIA.

Replies are listed 'Best First'.
Re: Net::Nslookup help needed
by oko1 (Deacon) on Aug 28, 2008 at 01:31 UTC

    Did you read the documentation for this module? Rather than guessing about what's happening (incidentally, your original script works just fine for me), try turning on the debugging option - just as the docs recommend. Since you're having problems, you should also specify the lookup type, as shown in the docs, instead of hoping for a reasonable default to be assigned.

    #!/usr/bin/perl -w use strict; use Net::Nslookup; $Net::Nslookup::DEBUG++; $Net::Nslookup::DEBUG_NET_DNS++; print "IP (A record): " . nslookup(host => "yahoo.com", type => 'A');

    Do note that most types of lookups actually return a list rather than a simple scalar. Again, the docs are pretty clear on the issue.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells
    
Re: Net::Nslookup help needed
by Khen1950fx (Canon) on Aug 27, 2008 at 23:28 UTC
    #!/usr/bin/perl use strict; use warnings; use Net::Nslookup; my $name = Net::Nslookup->nslookup; $name = nslookup( domain => 'yahoo.com' ); print "name=$name\n";
    Updated: added "name=$name\n"
      Thanks for the reply. That doesn't seem to help. The only difference is that I get this additional line from the debug:

      Performing 'A' lookup on `net::nslookup' at ...

      I don't know what the additional line is supposed to do but it appears that it is running nslookup using itself as the domain name.
Re: Net::Nslookup help needed
by Mr. Muskrat (Canon) on Aug 28, 2008 at 17:32 UTC

    Can you do an nslookup from a Command Prompt?

    G:\>nslookup yahoo.com Server: xxxxxxxxxxxxxxxx Address: xxx.xxx.xxx.xxx Name: yahoo.com Addresses: 68.180.206.184, 206.190.60.37