On Mar 26, 1:50*am, xhos...@gmail.com wrote:
> RedGrittyBrick <RedGrittyBr...@SpamWeary.foo> wrote:
>
> > I find it hard to understand what you are saying but I think the answer
> > is: Yes, Perl is well suited to programming with multiple threads (or
> > processes).
>
> I agree with the "(or processes)" part, provided you are running on a Unix
> like platform. *But in my experience/opinion Perl threads mostly suck.
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> this fact.
Here is my refactor code, which still at a very slow speed, please
advice me how to improve it, thanks very much:
require LWP:

arallel::UserAgent;
use HTTP::Request;
use LWP::Simple;
use threads;
# display tons of debugging messages. See 'perldoc LWP:

ebug'
#use LWP:

ebug qw(+);
my $reqs = [
HTTP::Request->new('GET',"http://www...."),
HTTP::Request->new('GET', "......"
..............# about nearly 200000 url here
];
my $pua = LWP:

arallel::UserAgent->new();
$pua->in_order (10000); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (1); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs) {
print "Registering '".$req->url."'\n";
if ( my $res = $pua->register ($req) ) {
print STDERR $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
threads->new(\&format_html, $res->content);
}
foreach my $thr (threads->list()) {
$thr->join(); # I think it does not work......
}
sub format_html {
my ($html_data) = shift;
my $word;
my $data;
while ( $html_data =~ m{...}igs ) {
$word = $1;
}
while ( $html_data =~ m{...}igs ) {
$data = $1;
save_data( $word, $data );
}
while ( $data =~ m{...}igs ) {
my $title = $1;
my $sound = $1.$2;
if ( defined($sound) ) {
save_sound( $word, $title, $sound );
}
}
}
sub save_data {
my ( $word, $data ) = @_;
open ( FH, " > ..." ) or die "Can not open $!";
print FH $data;
close(FH);
}
sub save_sound {
my ( $word, $title, $sound ) = @_;
getstore("...", "...") or warn $!;
}