in reply to To Hash or Not to Hash??
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: To Hash or Not to Hash??
by gwadej (Chaplain) on Dec 02, 2003 at 16:48 UTC |