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..
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.