Hi Ken,

Many thanks for your reply and also the reference link as well.

May I ask a bit further regarding the example code?

my $fetch; $fetch = sub { # Stop if there are no more URLs return unless my $url = shift @urls; # Fetch the next title my $end = $delay->begin; $ua->get($url => sub { my ($ua, $tx) = @_; say "$url: ", $tx->result->dom->at('title')->text; $end->(); # Next request $fetch->(); }); }; # Process two requests at a time $fetch->() for 1 .. 2; $delay->wait;
From the above code example, I believe this is an example of recursion.
There is condition to exit (return unless my $url = shift @urls;) and $fetch is calling itself within the sub $fetch.

I can understand the part with range operators to call how many times of $fetch.
But why if the range operator has been removed, i.e.
$fetch->(); $delay->wait;
Shouldn't the code process 1 request at a time until all the @urls have been processed?
But from my testing, it will only process the first url and then stop. Could you tell me more about this part?

Thanks,
Ronald

In reply to Re^2: coderef for 1 .. 2? by ronstudio
in thread coderef for 1 .. 2? by ronstudio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.