Elijah has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Thread; use LWP::UserAgent::ProxyAny; my $NumPerThread = 6; open(PROXY, "<", "proxies.txt") || die "No proxy list found!\n"; my @proxies = <PROXY>; close(PROXY); my ($thread, $cnt, @group); for (@proxies) { push(@group, $_); $cnt++; if ($cnt >= $NumPerThread) { $thread = new Thread \&process, @group; undef @group; undef $cnt; } } if (scalar @group) { $thread = new Thread \&process, @group; undef @group; } $thread->join; print "died with error $@\n" if ($@); print "Main Thread Exiting!\n"; sub process { my @section = @_; for (@section) { chomp(); my $ua = LWP::UserAgent::ProxyAny->new; $ua->set_proxy_by_name($_); $ua->timeout(2); my $response = $ua->get('http://www.google.com'); if ($response->is_success) { print "Connection using $_ was successfull!\n"; open(GOOD, ">>", "good_proxies.txt") || die "Unable to open good proxy list for writing: ($!)\n"; flock(GOOD, 2); print GOOD $_,"\n"; close(GOOD); }else{ print "Connection using $_ failed!\n"; } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Main thread exist before all worker threads?
by zentara (Cardinal) on Jul 07, 2005 at 18:31 UTC | |
Re: Main thread exist before all worker threads?
by sgifford (Prior) on Jul 07, 2005 at 19:11 UTC | |
Re: Main thread exist before all worker threads?
by eXile (Priest) on Jul 08, 2005 at 14:06 UTC |