Hi,
I am new at perl, using it for a month. It's a great language!
I need some help for threads, am trying to do threading but could not do that.
I have an script, which fetches data from internet, it's main structure is like this:
for ($i=0; $i<1000000; $i++) {
$content = get("http://www.somewebsite.com/news.php?id=$i");
print "Error!" unless defined $content;
... doing some trimming with regex ...
}
It actually does fetching more than 1000000 times. so, it takes long time. This is why i am trying to learn threads. I will use 10 threads.
However, I have $i value and am using it in the loop, so if I create 10 threads, it is doing same loop 10 times. I need something, which will do like;
for first thread :
http://www.somewebsite.com/news.php?id=1
http://www.somewebsite.com/news.php?id=11
http://www.somewebsite.com/news.php?id=21
http://www.somewebsite.com/news.php?id=31
...
for second thread
http://www.somewebsite.com/news.php?id=2
http://www.somewebsite.com/news.php?id=12
http://www.somewebsite.com/news.php?id=22
http://www.somewebsite.com/news.php?id=32
for third thread
http://www.somewebsite.com/news.php?id=3
http://www.somewebsite.com/news.php?id=13
http://www.somewebsite.com/news.php?id=23
http://www.somewebsite.com/news.php?id=33
.. and so on..
I have created 10 different sub routines and loops. Every loop is doing a part of fetching like;
first sub 1-100000
second sub 100000-200000
third sub 300000-400000
but it is not an elegant way of course. I would like to learn the correct format. i tried many things but could not success.
I also would like to change number of threads, so I guess, I also need to create a for loop for threads to do so. Then i can also change number of threads, but how?
Thanks from now on,
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.