There is an issue here. In your test structure you are testing for $our{'ns1.t'}, but ns1.t is a value not a key. What you would need to test for would be a key.. ala

my $ip = '24.56.102.10'; my %ours = ( 24.56.102.10 => 'ns1.t', ); if ( $ours{$ip} ) { print "Its there\n"; } else { print "Its not there\n"; }

If I am reading deep enough into what you are trying to do, I think you want to also reverse your %our and %theirs hashes. ala

$ours{$v} = $k while ( my($k, $v) = each %ours);

This way you can test for the existance of either the name of the host, or the IP address of the host.

On a side note in regards to style, it is better to pass the data you are going to be working on to your sub.

#... yada yada ... my %ips = ( ours => { 24.56.102.10 => 'ns1.t', }, theirs => { 68.168.192.17 => 'ns1.a', }, ); my @recs = nslookup( type => "NS", domain => $domain, ); ours(\%ips, \@recs); # .. yada yada .. sub ours { my($ip, $recs) = @_; for ( @$recs ) { if ( $ip->{ours}{$_} ) { print OUT "$_\n"; } elsif ( $ip->{theirs}{$_} ) { print OUT1 "$_\n"; } else { # do we care about this case? } } }

This way its clear exactly what is going where, and what data is being worked on. As opposed to digging into the sub, figuring out what variables are used, determine their scope, etc..

use perl;


In reply to Re: To Hash or Not to Hash?? by l2kashe
in thread To Hash or Not to Hash?? by sunadmn

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.