in reply to How to do multiple dns queries ?

Try what jaldhar suggested, but if you want to learn how to use thread, check out the attached code, which is a multi-thread version of your code.
use strict; use warning; use Net::DNS; use threads; sub resolve { my $res = Net::DNS::Resolver>new; $res->nameservers(); my ($nameserver, $url) = @_; my $query = $res->search($url); $res->print; my $result; if ($query) { foreach my $rr ($query>answer) next unless $rr->type eq "A"; $result = $rr->address; } } return [$url, $result]; } my $nameserver = "12.104.122.2"; my @url = ("www.perlmonks.com", "www.foxnews.com"); my @thread_pool; foreach my $url @url { push @thread_pool, threads->new(\&resolve, $nameserver, $url); } my @result; foreach my $thread @thread_pool { push @result, $thread->join; }

Replies are listed 'Best First'.
Re: Re: How to do multiple dns queries ?
by gnangia (Scribe) on Nov 24, 2002 at 03:23 UTC
    When I run the above program, I get the following error -
    Can't locate threads.pm in @INC (@INC contains: /usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/si te_perl/5.6.0 /usr/lib/perl5/site_perl .) at ./dns2.pl line 8.
    BEGIN failed--compilation aborted at ./dns2.pl line 8.
    Is this a verion 5.6.1 thing ?