Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
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
    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 examining the Monastery: (14)
As of 2015-07-29 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (268 votes), past polls