Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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]
[Corion]: Hmmm. I feel a Meditation coming on. I wrote a module, DBIx::PivotQuery, which returns a table-like set of rows (AoA) but some columns are generated from column values, like in an (Excel) pivot table or a ROLLUP command
[Corion]: My current approach for subtotals involves rerunning the given query, with the hint to the user that they should use a temporary table if they want better performance.
[Corion]: But I could create that temporary table in the module and use it for the improved perfomance directly instead.
[Corion]: And the question is, what would be better/preferred ;-)
[Corion]: Hmm - not exactly like the ROLLUP command. Ah well.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-02-23 15:26 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (347 votes). Check out past polls.