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

Monks,

I'm wanting to use Net::Whois::IP but I'm not sure how to obtain the data after doing the query. Here is what the documentation states:
use Net::Whois::IP qw(whoisip_query); my $ip = "192.168.1.1"; #Response will be a reference to a hash containing all information #provided by the whois registrar #The array_of_responses is a reference to an array containing referenc +es #to hashes containing each level of query done. For example, #many records have to be searched several times to #get to the correct information, this array contains the responses #from each level my ($response,$array_of_responses) = whoisip_query($ip);
I have to admit, I'm not too clear on references even after reading perlref. I would most appreciate any assistance the monastary might be able to provide.

Thanks,
-Dru

Replies are listed 'Best First'.
Re: Help Dereferencing Net::Whois::IP
by castaway (Parson) on Jun 20, 2003 at 12:33 UTC
    Taking the hash reference, turning it into a hash, and looping through the hash should do it, something like this:
    my ($response,$array_of_responses) = whoisip_query($ip); my %hresponse = %{$response}; while (my ($key, $value) = each %hresponse) { print "value of $key is $value\n"; }

    Does that help?
    C.

      You can avoid the temporary here:
      my ($response,$array_of_responses) = whoisip_query($ip); while (my ($key, $value) = each %$response) { print "value of $key is $value\n"; }

      Makeshifts last the longest.

Re: Help Dereferencing Net::Whois::IP
by bobn (Chaplain) on Jun 20, 2003 at 12:55 UTC
    When trying to decode an object retured to you, Data::Dumper can be your best friend.

    In this case,
    use Net::Whois::IP qw(whoisip_query); use Data::Dumper; my $ip = "192.168.1.1"; my ($response,$array_of_responses) = whoisip_query($ip); print '$response is: ', Dumper( $response ); print '$array_of_responses is: ', Dumper( $array_of_responses) +;
    reslt is:
    $response is: $VAR1 = { 'OrgTechName' => 'Internet Corporation for Assigned Names an +d Number ', 'NameServer' => 'BLACKHOLE-2.IANA.ORG', 'Country' => 'US', 'PostalCode' => '90292-6695', 'OrgTechEmail' => 'res-ip@iana.org', 'RegDate' => '1994-03-15', 'NetHandle' => 'NET-192-168-0-0-1', 'NetName' => 'IANA-CBLK1', 'OrgTechPhone' => '+1-310-823-9358', 'City' => 'Marina del Rey', 'OrgName' => 'Internet Assigned Numbers Authority ', 'Comment' => ' ', 'Address' => '4676 Admiralty Way, Suite 330', 'OrgTechHandle' => 'IANA-ARIN', 'NetType' => 'IANA Special Use', 'CIDR' => '192.168.0.0/16 ', 'StateProv' => 'CA', 'Updated' => '2002-09-16', 'OrgID' => 'IANA', 'NetRange' => '192.168.0.0 - 192.168.255.255 ', 'Parent' => 'NET-192-0-0-0-0' }; $array_of_responses is: $VAR1 = undef;
    The 'Var1 =' is just window-dressing added by Data::Dumper. The rest of the output looks like a hash, but is conatinined in {} rather than (), so it is a reference to hash. hence it is dereferenceed with ->. So to get the Tech contact's email, you'd say:
    print "Tech contact's email is $response->{OrgTechEmail}\n";
    Unfortunately, the keys in the hash erference are different depending on the registrar - using my IP address, I return a hashref where the Tech contact' email is accessed by:
    print "Tech contact's email is $response->{TechEmail}\n";


    --Bob Niederman, http://bob-n.com
      Wow, Data::Dumper rocks, thanks Bob and to the others for your response.
Re: Help Dereferencing Net::Whois::IP
by ScooterQ (Pilgrim) on Jun 20, 2003 at 12:38 UTC
    Are you just looking to get a handle on dereferencing? If so, perhaps this will help: $reponse is a reference to a hash - a hash "thingy". $array_of_responses is an array "thingy". Perhaps the simplest way to get your head around it is to think of it like this:
    my ($response,$array_of_responses) = whoisip_query($ip); %resp_hash = %$response; @resp_array = @$array_of_responses;
    At this point you have the regular ol' hash and array like you're used to dealing with. Now, of course, you could have skipped the additional assignment and done things in a more direct manner, working with the de-referenced hash and array rather than copying them like I did, but this slightly more verbose manner is the way I was first able to understand references and de-referencing.

    HTH.