Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Passing multiple arguments to CallBack routine.

by mr_p (Scribe)
on May 23, 2013 at 17:15 UTC ( #1034992=perlquestion: print w/ replies, xml ) Need Help??
mr_p has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys,

I wanted to add $depth into the @urls with separated by pipe '|' symbol, Is it possible to pass multiple arguments to the callback routine?

So, I would like to pass $depth as argument to depth, if its possible.

Thanks.

Here is an Example code.

Mojo::IOLoop->recurring( 0 => sub { for ($active + 1 .. $max_conn) { # Dequeue or halt if there are no active crawlers anymore return ($active or Mojo::IOLoop->stop or $totalPagesVisite +d > $maxPages) unless my $url = shift @urls; # Fetch non-blocking just by adding # a callback and marking as active ++$active; say "getting link: $url"; ($depth, $myLink) = split ('\|', $url); $ua->get($myLink => \&get_callback); } } ); sub get_callback { my (undef, $tx) = @_; ...... push(@urls, "$depth+1|$newLink"); ...... }

Comment on Passing multiple arguments to CallBack routine.
Download Code
Re: Passing multiple arguments to CallBack routine.
by mr_p (Scribe) on May 23, 2013 at 17:37 UTC
    I got my own answer.

      Perhaps you could share it with us so that other monks who might have the same query and see your post can find a solution :-)

      Cheers,

      JohnGG

        This is what I am using now.
        if ($myDepth < ($maxDepth +1 ) ) { my $tx=$ua->get($url); get_callback(\$tx, $myDepth+1); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-05 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls