but it failed throwing the below error:

Hm . Runs fine under 5.8.9.

Also, in my original prg, I was trying to download 200 different files changing the URL each time, but in the prg that you gave, looks like it downloads a single file 200 times.. is that right ?

Sorry. I don't have a handy source of 200 different files at my disposal.

#! perl -slw use strict; use threads ( stack_size => 4096 ); use threads::shared; use LWP::Simple; use Time::HiRes qw[ time sleep ]; our $T ||= 200; ## This can be change by a command line arguement -T=n +nn my $url = ## your url here ##; ## This shared variable counts ## the number of running threads my $running :shared = 0; ## This records the start time my $start = time; ## For 1 to 200 for( 1 .. $T ) { ## start a new thread async( ## running this sub sub{ ## Increment the running threads count { lock $running; ++$running }; ## Make all threads wait until all threads are running ## so that the download requests all hit the server at the + same time sleep 0.001 while $running < $T; ## The number (1..200) passed in as $_ below. my $id = shift; ## get $url and store it in a file with $id as part of the + name getstore( $url, qq[c:/test/dl.t.$id] ); ## Now this thread is finished, decrement the count lock $running; --$running; }, $_ ## $_ (1..$T) becomes $id inside. ## Detach means that the threads go away as soon as they are done. ## Rather than hanging around consuming resources waiting to retur +n ## a return value to join that we have no interest in. )->detach; } ## Now the main thread just sleeps till all the d/l threads have finis +hed. sleep 1 while $running; ## And tells you how long the whole thing took printf "Took %.3f seconds\n", time() - $start;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^5: Perl threads to open 200 http connections by BrowserUk
in thread Perl threads to open 200 http connections by robrt

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.