我寫了一個代碼,我需要使它成爲多線程。 Evething作品,但每一個循環重複4次:線程共享的Perl
use LWP::UserAgent;
use HTTP::Cookies;
use threads;
use threads::shared;
$| = 1;
$threads = 4;
my @groups :shared = loadf('groups.txt');
my @thread_list =();
$thread_list[$_] = threads->create(\&thread) for 0 .. $threads - 1;
$_->join for @thread_list;
thread();
sub thread
{
my $url = 'http://www.site.ru/';
my $response = $web->post($url, Content =>
['st.redirect' => ''
]);
foreach $i (@groups)
{
my $response = $web->get($i);
if(!($response->header('Location')))
{
---------;
}
else
{
----------;
}
}
}
sub loadf {
open (F, "<".$_[0]) or erroropen($_[0]);
chomp(my @data = <F>);
close F;
return @data;
}
groups.txt:
http://www.odnoklassniki.ru/group/47357692739634
http://www.odnoklassniki.ru/group/56099517562922
我明白,我需要使用::共享線程;但我不能忍受如何使用它。
您的帖子沒有太多的上下文來解釋代碼段;請更清楚地解釋你的情況。
你期望什麼行爲?你得到了什麼?你可以刪除代碼中不重要的部分來提供一個簡單的例子嗎?請參閱http://sscce.org/ – amon