Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Need help with script with a while loop reading file

by blue_cowdawg (Monsignor)
on May 03, 2013 at 13:57 UTC ( #1031896=note: print w/ replies, xml ) Need Help??


in reply to Need help with script with a while loop reading file

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"; } } }
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.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Need help with script with a while loop reading file
Download Code
Re^2: Need help with script with a while loop reading file
by brianjb (Novice) on May 03, 2013 at 14:34 UTC
    Thank you for the quick response. Definitely forgot the chomp.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-10-23 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (126 votes), past polls