Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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(], ); 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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031896]
[stevieb]: so, it's -34c today, and some of my water pipes are frozen and one burst. sigh
[stevieb]: it doesn't seem as though "there's an app for that"
[ambrus]: burst water pipe sucks
[Corion]: ambrus: Ugh - yes, that really sucks!
[stevieb]: good thing is that both sides of the break are completely frozen, so I was able to shut off the water to the building before any water leaks. I told the landlord last year to insulate that specific area better
[Corion]: stevieb: Our SV overlords don't know what "frozen pipe" means and think it's something like "frozen yogurt"

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2016-12-08 18:03 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (144 votes). Check out past polls.