in reply to Need help with script with a while loop reading file
I admit I am showing my prejudice here, but I prefer to use implicit variables. That said, note the minor modifications I made to your code, the most important being the "chomp" to remove the EOL from the string. Otherwise you are looking up a hostname that ends in EOL.while (my $hname =<FILE>) { chomp $hname; my $res = Net::DNS::Resolver->new( nameservers => [qw(8.8.8.8)], ); my $query = $res->search($hname); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print "Found an A record for $_: ".$rr->address; print "\n"; } } }
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Need help with script with a while loop reading file
by brianjb (Novice) on May 03, 2013 at 14:34 UTC |
In Section
Seekers of Perl Wisdom