I did a script with Net::Whois that worked fine - running in a DOS window (I have ActiveState Perl, Win32 system). When I modified the script to use Tk, it works, but, the first time I pass it a domain name that is not found, I get a warning message from Net::Whois
Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 288 ( +#1) Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 289 ( +#1) Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 294 ( +#1) Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 297 ( +#1)
and I've taken a look at the whois.pm, using those lines as a reference, but haven't a clue how to correct, or why it does not give me a warning when I use the script that only runs in the DOS window.

I have included the Tk verision of the script first, and below that the DOS window version (and I hope that I have done the code tags properly!)

I'm still a perl 'newbie' and I'm stumped! The Tk version seems to be passing? something different? to Net::Whois, but I can't figure out what.

Thank you!

#!/perl -w # tk_whois_perl.pl # july, 2001 # uses the Net::Whois module to query the Internic DNS for domain name +s # uses Tk for input and output display # warning message first time an unfound match, # thereafter no message just the not found message box # #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 288 +(#1) #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 289 +(#1) #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 294 +(#1) #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 297 +(#1) # #fgsgsdgsdg.com not found # from the whois documentation - Note that all fields except ``name'' +and ``tag'' # may be undef because ``whois'' information is erratically filled in. + use diagnostics; use strict; use Tk; use Tk::widgets qw/Dialog/; require Tk::ROText; #require Tk::LabEntry; use Net::Ping; use Net::Whois; #------------------------------------------------- my $main = new MainWindow; my $domain_input_entry; my $domain_output_text_box; online_test(); init(); MainLoop; #------------------------------------------------- sub online_test { my $online_check = check_if_online(); if ( $online_check eq "N" ) { $main->withdraw; # do not show my $msgbox_not_online_text = "\n\nmust be online to use whois\n\nreturn to menu to dial +up\n"; my $msgbox_not_online = $main->messageBox(-icon => 'warning +', -message => "$msgbox_not_online_text", -title => 'not online', -type => 'OK'); $main->destroy; exit; } } # end of online_test #------------------------------------------------- sub init { # create frame and input label and entry; submit and exit whois button +s my $input_frame = $main->Frame(qw/-width 450 -height 250/)->pack; my $domain_info_label = $input_frame->Label(-text => 'lookup whois inf +ormation from the InterNIC server'); my $domain_input_label = $input_frame->Label(-text => 'enter domain na +me to search for'); $domain_input_entry = $input_frame->Entry(-width => 25); # to bind the pressing of enter key to the domain_sub as the button do +es in -command $main->bind('<KeyPress-Return>' => sub{check_input_entry($domain_input +_entry)}); my $input_button = $input_frame->Button(-text => 'submit', -width => 6, -command => sub{check_input_entry($domain_input_entry)}); my $exit_button = $input_frame->Button(-text => 'exit', -width => 6, -command => sub{exit}); # pack $domain_info_label->pack(-side => 'top', -fill => 'both', -expand => 1); $domain_input_label->pack(-side => 'left', -expand => 1); $domain_input_entry->pack(-side => 'left', -expand => 1); $exit_button->pack(-side => 'right', -expand => 1, -anchor => 'e', -padx => 6, -pady => 2); $input_button->pack(-side => 'right', -expand => 1, -anchor => 'e', -padx => 6, -pady => 2); # create the frame for the output text my $output_frame = $main->Frame(qw/-width 450 -height 300 -background +gray/)->pack; $domain_output_text_box = $output_frame->ROText(-relief => 'sunken', -width => 60, -height => 15, -wrap => 'word', -setgrid => 1); my $scroll = $output_frame->Scrollbar(-command => ['yview', $domain_ou +tput_text_box]); $domain_output_text_box->configure(-yscrollcommand => ['set', $scroll] +); $domain_output_text_box->pack(-side => 'left', -fill => 'both', -expan +d => 1); $scroll->pack(-side => 'right', -fill => 'y'); $domain_input_entry->focus; # set the focus to the entry box } # end init #------------------------------------------------- sub check_input_entry { my($widget) = @_; my $domain_name = $widget->get(); chomp($domain_name); if ( $domain_name =~ /(.org|.com|.edu|.net$)/ ) { # domain type was acceptable, so pass +the domain_sub($domain_name); # domain name to the domain_sub t +o contact clear_entry(); # the whois server } else { my $msgbox_unacceptable_domain_entered_text = "\n\ndomain name must end in .org, .com, .edu or .net\n\ne +nter domain or exit whois\n\n"; my $msgbox_unacceptable_domain_entered = $main->messageBox(-ic +on => 'warning', -message => "$msgbox_unacceptable_domain_enter +ed_text", -title => 'unacceptable domain type entered' +, -type => 'OK'); if ( $msgbox_unacceptable_domain_entered eq "ok" ) { clear_entry(); } } # end of if domain_name } # end of sub check_imput_entry #------------------------------------------------- sub domain_sub { # this is called from check_input_entry the $domain_name is passed to +the sub # $domain_name was acceptable type, so check in whois my $domain_name = shift; my($domain_obj) = ""; clear_output(); # clear the output text box # first check if whois server is available $domain_obj = Net::Whois::Domain->new($domain_name) or fatal_error +(); #or die "can't connect to whois server to get information on $doma +in_name: $!\n"; # server is available if ( $domain_obj->ok ) { # call methods on $domain_obj to get name, tag, address, etc. #print "The domain is called ", $domain_obj->domain, "\n"; $domain_output_text_box->insert('end', "\nThe domain is called ".$ +domain_obj->domain."\n"); #print "Its tag is ", $domain_obj->tag, "\n"; $domain_output_text_box->insert('end', "Its tag is ".$domain_obj-> +tag."\n"); #print "Mail for ", $domain_obj->name, " should be sent to:\n"; $domain_output_text_box->insert('end', "Mail for ".$domain_obj->na +me." should be sent to:\n"); #print map { "\t$_\n" } $domain_obj->address; $domain_output_text_box->insert('end', $domain_obj->address."\n"); #print "\t", $domain_obj->country, "\n"; $domain_output_text_box->insert('end', $domain_obj->country."\n"); my $contact_hash = $domain_obj->contacts; if ($contact_hash) { #print "Contacts:\n"; $domain_output_text_box->insert('end', "Contacts:\n"); foreach my $type (sort keys %$contact_hash) { #print " $type:\n"; $domain_output_text_box->insert('end', " ".$type.":\n"); foreach my $line (@{$contact_hash->{$type}}) { #print " $line\n"; $domain_output_text_box->insert('end', " ".$line."\ +n"); } } } else { #print "no contact information.\n"; $domain_output_text_box->insert('end', "no contact information +\n"); } #print "Name Servers: \n"; $domain_output_text_box->insert('end', "Name Servers: \n"); #printf " %s (%s)$/", @$_ for @{$domain_obj->servers}; foreach (@{$domain_obj->servers}) { $domain_output_text_box->insert('end', " ".$$_[0]." (".$ +$_[1].")\n"); } #print "\n"; $domain_output_text_box->insert('end', "\n"); #print "Record created: ", $domain_obj->record_created, "\n"; $domain_output_text_box->insert('end', "Record created: ".$domain_ +obj->record_created."\n"); #print "Record updated: ", $domain_obj->record_updated, "\n"; $domain_output_text_box->insert('end', "Record updated: ".$domain_ +obj->record_updated."\n"); } else { my $msgbox_no_domain_found_text = "\n\n$domain_name not found\n\n" +; my $msgbox_no_domain_found = $main->messageBox(-icon => 'warnin +g', -message => "$msgbox_no_domain_found_text", -title => 'no domain found', -type => 'OK'); # warning message first time an unfound match, thereafter no message j +ust the # not found message box #c:/perl/scripts/tk_whois_perl.pl # #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 288 +(#1) # # (W) An undefined value was used as if it were already defined. I +t was # interpreted as a "" or a 0, but maybe it was a mistake. To suppr +ess this # warning assign an initial value to your variables. # #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 289 +(#1) #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 294 +(#1) #Use of uninitialized value at C:/PERL/site/lib/Net/Whois.pm line 297 +(#1) # #fgsgsdgsdg.com not found #Note that all fields except ``name'' and ``tag'' may be undef because + #``whois'' information is erratically filled in. #print "\n$domain_name not found\n\n"; } # end of if $domain_obj->ok } # end of domain_sub #------------------------------------------------- sub clear_entry { # clear the entry box # set the focus $domain_input_entry->delete(0, 'end'); $domain_input_entry->focus; } #------------------------------------------------- sub clear_output { # clear out the output text box $domain_output_text_box->delete('1.0','end'); } #------------------------------------------------- sub check_if_online { my $online_check; # check if already online by pinging dialup server my $host = "208.59.251.68"; my $p = Net::Ping->new() or die "can't create new ping object: $!\ +n"; if ( $p->ping($host) ) { $online_check = "Y"; } else { $online_check = "N"; } $p->close; return $online_check; } #------------------------------------------------- sub fatal_error { my $msgbox_unable_to_contact_text = "\n\ncan't contact server or s +erver busy\n\$!\nexiting whois\n"; my $msgbox_unable_to_contact = $main->messageBox(-icon => ' +error', -message => "$msgbox_unable_to_contact_tex +t", -title => 'unable to contact server', -type => 'OK'); $main->destroy; exit; } #------------------------------------------------- ------------------------------------------------------------------ # original script that produces no warnings running in DOS window #!/perl -w # whois_perl.pl use diagnostics; use strict; use Net::Whois; use Net::Ping; my($domain_obj); # get input my $online_check = check_if_online(); if ( $online_check eq "N" ) { print "\n\nmust be online to use whois\n\n"; print "\nreturn to internet_perl menu to dialup\n\n"; exit; } else { print "\n\nenter domain name to search for: \n\n"; my $domain_name=<STDIN>; chomp($domain_name); if ( $domain_name eq "" ) { print "\n\nyou didn't enter anything\n\n"; print "return to internet_perl menu\n\n"; exit; } else { $domain_obj = Net::Whois::Domain->new($domain_name) or die "can't connect to whois server to get information on $d +omain_name: $!\n"; if ( $domain_obj->ok ) { # call methods on $domain_obj to get name, tag, address, etc. print "The domain is called ", $domain_obj->domain, "\n"; print "Its tag is ", $domain_obj->tag, "\n"; print "Mail for ", $domain_obj->name, " should be sent to:\n"; print map { "\t$_\n" } $domain_obj->address; print "\t", $domain_obj->country, "\n"; my $contact_hash = $domain_obj->contacts; if ($contact_hash) { print "Contacts:\n"; foreach my $type (sort keys %$contact_hash) { print " $type:\n"; foreach my $line (@{$contact_hash->{$type}}) { print " $line\n"; } } } else { print "no contact information.\n"; } print "Name Servers: \n"; printf " %s (%s)$/", @$_ for @{$domain_obj->servers}; print "\n"; print "Record created: ", $domain_obj->record_created, "\n"; print "Record updated: ", $domain_obj->record_updated, "\n"; } else { print "\n$domain_name not found\n\n"; } } } #################################################### sub check_if_online { my $online_check; # check if already online by pinging dialup server my $host = "208.59.251.68"; my $p = Net::Ping->new() or die "can't create new ping object: $!\ +n"; if ( $p->ping($host) ) { $online_check = "Y"; } else { $online_check = "N"; } $p->close; return $online_check; } ####################################################

In reply to Net::Whois problem using Tk by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.