Hello Monks,

I'm having a problem with the below code. When I run this code with strict enabled, I get the following error:
:!./temp site Can't use string ("ftp.siebel.com") as a HASH ref while "strict refs" in use at ./temp line 51. shell returned 255
if I disable strict, I get:
site Use of uninitialized value in concatenation (.) or string at ./temp line 51. site -> Use of uninitialized value in concatenation (.) or string at ./temp line 52. site -> ftp.siebel.com ftp.siebel.com -> 64.181.143.36 ftp.siebel.com -> 64.181.143.36 ebusiness.siebel.com ebusiness.siebel.com -> 64.181.189.50 ebusiness.siebel.com -> 64.181.189.50 www.siebel.com www.siebel.com -> 64.181.189.55 www.siebel.com -> 64.181.189.55 messenger.hotmail.com messenger.hotmail.com -> 207.46.104.20 messenger.hotmail.com -> 207.46.104.20
I can't figure out why I'm getting an empty entry. Hashes always seem to drive me bonkers, but I think it's the best data structure to use in this scenario. I would appreciate any help.
1 #!/usr/bin/perl -w 2 # 3 # lookup.pl - Check if these sites have changed their ip address 4 # 5 6 #use strict; 7 use Net::Nslookup; 8 use Mail::Sender; 9 10 my %hash; 11 12 # MSN Messenger 13 my $msndns = 'messenger.hotmail.com'; 14 my $msnip = '207.46.104.20'; 15 my $msn = nslookup(host => "$msndns", type => "A"); 16 17 $hash{site} = $msndns; 18 $hash{$msndns}{ip_now} = $msnip; 19 $hash{$msndns}{ip_new} = $msn; 20 21 # www.siebel.com 22 my $www_siebel_dns = 'www.siebel.com'; 23 my $www_siebel_ip = '64.181.189.55'; 24 my $www_siebel = nslookup(host => "$www_siebel_dns", type => "A"); 25 26 $hash{site} = $www_siebel_dns; 27 $hash{$www_siebel_dns}{ip_now} = $www_siebel_ip; 28 $hash{$www_siebel_dns}{ip_new} = $www_siebel; 29 30 # ebusiness.siebel.com 31 my $ebiz_siebel_dns = 'ebusiness.siebel.com'; 32 my $ebiz_siebel_ip = '64.181.189.50'; 33 my $ebiz_siebel = nslookup(host => "$ebiz_siebel_dns", type => "A" +); 34 35 $hash{site} = $ebiz_siebel_dns; 36 $hash{$ebiz_siebel_dns}{ip_now} = $ebiz_siebel_ip; 37 $hash{$ebiz_siebel_dns}{ip_new} = $ebiz_siebel; 38 39 # ftp.siebel.com 40 my $ftp_siebel_dns = 'ftp.siebel.com'; 41 my $ftp_siebel_ip = '64.181.143.36'; 42 my $ftp_siebel = nslookup(host => "$ftp_siebel_dns", type => "A"); 43 44 $hash{site} = $ftp_siebel_dns; 45 $hash{$ftp_siebel_dns}{ip_now} = $ftp_siebel_ip; 46 $hash{$ftp_siebel_dns}{ip_new} = $ftp_siebel; 47 48 49 for my $j ( keys(%hash) ){ 50 print "$j\n"; 51 print "$j -> $hash{$j}{ip_now}\n"; 52 print "$j -> $hash{$j}{ip_new}\n"; 53 }

In reply to Problem with Hash when Using Strict by Dru

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.