我写了一个代码,我需要使它成为多线程。 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