Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

optimise code EV Event AnyEvent POE

by swilting (Beadle)
on Jun 26, 2012 at 00:07 UTC ( #978307=perlquestion: print w/ replies, xml ) Need Help??
swilting has asked for the wisdom of the Perl Monks concerning the following question:

hello guys hello monks hello master

i love coding for fun and right now I write a small cgi script to check rbl this my code

https://gitorious.org/check-rbl-cgi-perl/check-rbl-cgi-perl/blobs/master/rblcheck.pl

work well for fun but I've heard of EV and AnyEvent and lack of documentation . and now I reclame a little help to continue to code with EV and AnyEvent. I want someone to show me a simple example with EV that could be used in my case

any idea ... sincerely

Comment on optimise code EV Event AnyEvent POE
Re: optimise code EV Event AnyEvent POE
by Anonymous Monk on Jun 26, 2012 at 05:08 UTC

    work well for fun but I've heard of EV and AnyEvent and lack of documentation . and now I reclame a little help to continue to code with EV and AnyEvent.

    :) But did you look for yourself? Even at examples in MANIFEST?

    I want someone to show me a simple example with EV that could be used in my case

    Can you be specific about what you wish to accomplish?

    To me, using POE/EV doesn't seem useful for straight HTTP. I think a better step would be to background the potentially costly step, see Watching long processes through CGI (Aug 02)

    Here is one tip for you, you should remove all prototypes sub blah($) because you don't make use of them, they just extra typing -- see Modern Perl for some tips on that

    Another tip is to confine your pogram to a single function called Main, see (tye)Re: Stupid question (and one discussion of that template Re^2: RFC: Creating unicursal stars) -- Modern Perl also has an example

Re: optimise code EV Event AnyEvent POE
by Corion (Pope) on Jun 26, 2012 at 07:18 UTC

    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__ google.de google.com example.com doesnotexist.local perlmonks.org

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://978307]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-16 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls