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

Hi all, I have the code below: The problem is that I'm getting a
Can't call method "search" on an undefined value at ./test.pl line 8.
Now, this may or may not be a general question on subroutines, or it may be a net::dns one specifically, I'm not sure. Any help or pointers would be appreciated.
use NetAddr::IP; use Net::DNS::Resolver; sub reverselookup($) { my ($ip) = @_; my $search = $res->search($ip); foreach $rr ( $search->$answer) { my $type=$rr->type; if ($type eq "A") { $host=$rr->address; } if ($type eq "PTR") { $host=$rr->ptrdname; } } } &reverselookup("61.9.128.17");
...found the problem....no new resolve declared.... <feels stupid>

Replies are listed 'Best First'.
Re: Net::DNS::Resolver problem with subroutine.
by fluxion (Monk) on Jun 27, 2004 at 13:47 UTC
    my ($ip) = @_;

    should be

    my ($ip) = $_[0];

    or

    my $ip = shift;

    disregard. <also feels stupid>

    Roses are red, violets are blue. All my base, are belong to you.