Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: optimise code EV Event AnyEvent POE

by Corion (Pope)
on Jun 26, 2012 at 07:18 UTC ( #978345=note: print w/replies, xml ) Need Help??

in reply to optimise code EV Event AnyEvent POE

Using AnyEvent::DNS, you could parallelize your DNS requests to the various blacklists instead of waiting for the results sequentially.

#!perl -w use strict; use AnyEvent; use AnyEvent::DNS; my %results; my $outstanding = AnyEvent->condvar; for my $domain (<DATA>) { $domain =~ s!\s+$!!; # Fire off a query for this hostname warn "Querying ip(s) for '$domain'"; $outstanding->begin(); AnyEvent::DNS::resolver->resolve ( $domain, "a", sub { $outstanding->end; if( @_ ) { for (@_) { my ($name, $type, $in, $ttl, $ip) = @$_; $results{ $name } ||= []; warn "Response for $name"; push @{$results{ $name }}, $ip; }; } else { warn "No response for $domain"; }; }); }; # Wait for all requests to finish $outstanding->recv; use Data::Dumper; warn Dumper \%results; __DATA__ doesnotexist.local

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978345]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2017-11-24 06:35 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (345 votes). Check out past polls.