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

Hi Monks,

I'm having some issues with Net::Whois::IP. If I query and ip that has only one single record (129.1.1.1 for example - just a random ip BTW) I do not have any problems. But if I query on an ip that has more then one record (149.1.1.1 for example) then I get the oh so lovely Use of uninitialized value in concatenation (.) or string message. If you do not know what I mean by record, you can search the ARIN db here and just enter each of the ip's above to see what I mean. Here is my code that I am using:
use strict; use warnings; use Net::Whois::IP qw(whoisip_query); use Data::Dumper; &whois(); my ($ip, $email, $techname); print "$ip\'s name is $techname and email address is $email\n"; sub whois{ $ip = '149.1.1.1'; my ($response,$array_of_responses) = whoisip_query($ip); $email = $response->{TechEmail}; $techname = $response->{TechName}; return ($email, $techname);
Thanks again monks.

Replies are listed 'Best First'.
Re: Help With Net::Whois::IP
by mr_mischief (Monsignor) on Jul 02, 2003 at 17:42 UTC
    Let's look at your code line-by-line...
    use strict; # good use warnings; # good use Net::Whois::IP qw(whoisip_query); # I can't test as I don't have the Net::Whois::IP # module installed use Data::Dumper; # Here is a module you invoke but from which you don't # call anything, at least in this example. &whois(); # why do you call this with no params # and use lexicals form the $main:: # package within it? This is not # directly related to your problem, but # is bad form. You also call it in void # context even though you make it return # values... my ($ip, $email, $techname); # The above call returns things that are not # declared until here. Think about what my() will # do to these variables at this point in the program. print "$ip\'s name is $techname and email address is $email\n"; # There's a concatenation done here. Is this # the line that complains? Why would these variables # not be initialized? sub whois{ $ip = '149.1.1.1'; my ($response,$array_of_responses) = whoisip_query($ip); $email = $response->{TechEmail}; $techname = $response->{TechName}; return ($email, $techname); # Here you return something # which your main program # is throwing away because # the sub is called in # void context. ####!!! There should be a closing curly for this sub!!!
    I can't test anything right now because I don't have the time to install Net::Whois::IP for just a test. However, let's see if you get the same error with the following code. Even if you do, it may be easier to track down.
    use strict; use warnings; use Net::Whois::IP qw(whoisip_query); use Data::Dumper; my ($ip, $email, $techname); $ip = '149.1.1.1'; ( $email, $techname ) = whois($ip); print "$ip\'s name is $techname and email address is $email\n"; sub whois { my $addr = shift; my ($response,$trash) = whoisip_query($addr); $email = $response->{TechEmail}; $techname = $response->{TechName}; return ($email, $techname); }


    Christopher E. Stith
      Thanks for taking the time to reply. My messy code was a result of some testing thus the strange scoping. I used your code and the one from the first problem and I'm having the same problem.
        I would try printlining the variables which are used in that line to see the values. This may be something specific to the module you are using not doing what you expect.

        Christopher E. Stith
Re: Help With Net::Whois::IP
by tcf22 (Priest) on Jul 02, 2003 at 17:30 UTC
    You are $ip in the string directly after my($ip), so you are using an undefined variable in the print statement. How about something like this
    use strict; use warnings; use Net::Whois::IP qw(whoisip_query); use Data::Dumper; my $ip = '149.1.1.1'; my ($email, $techname) = &whois($ip); print "$ip\'s name is $techname and email address is $email\n"; sub whois{ my $ip = $_[0]; my ($response,$array_of_responses) = whoisip_query($ip); my $email = $response->{TechEmail}; my $techname = $response->{TechName}; return ($email, $techname); }
Re: Help With Net::Whois::IP
by tcf22 (Priest) on Jul 02, 2003 at 19:35 UTC
    I used Data::Dumper to display the contents of $response. It looks like the key names that I get back aren't TechEmail & TechName. They are actually OrgTechEmail & OrgTechName. &whois() is actually returning (undef, undef). That is why you are getting unitialized value.
Re: Help With Net::Whois::IP
by Mr. Muskrat (Canon) on Jul 02, 2003 at 19:49 UTC
    Here's my compilation of the different code examples and clarifications:
    #!/usr/bin/perl use strict; use warnings; use Net::Whois::IP qw(whoisip_query); foreach my $ip qw(129.1.1.1 149.1.1.1) { my ($email, $techname) = whois($ip); print "$ip\'s name is $techname and email address is $email\n"; } sub whois { my $addr = shift; my $response = whoisip_query($addr); my $email = $response->{TechEmail} || $response->{OrgTechEmail}; my $techname = $response->{TechName} || $response->{OrgTechName}; return ($email, $techname); }

    Don't upvote this... go upvote the people who came up with the different bits that I combined.

Re: Help With Net::Whois::IP
by Dru (Hermit) on Jul 02, 2003 at 18:57 UTC