in reply to Re: Fork Me I need help
in thread Fork Me I need help
I would use something like:
use warnings 'all'; use strict; use Email::Valid::Loose; use Net::DNS; use Fcntl qw /:flock :seek/; ... setup stuff ... sub check_addresses; open my $bad => "> badmails" or die "Failed to open badmails: $!\ +n"; open my $good => "> goodmails" or die "Failed to open goodmails: $! +\n"; my $chunk_size = int (@adds / 20) + 1; while (@adds) { my @chunk = splice @chunks, 0, $chunk_size; my $pid = fork; die "Failed to fork: $!\n" unless defined $pid; unless ($pid) { check_addresss @chunk; exit; } } 1 until wait () == -1; # Wait till all children have died. exit; sub check_addr { my $address = shift; ... do some test, return 1 if good, 0 if bad ... } sub check_addresses { foreach my $address (@addresses) { my $handle = check_addr ($address) ? $good : $bad; flock $handle, LOCK_EX or die "Flock failed: $!\n"; seek $handle, SEEK_END, 0 or die "Seek failed: $!\n"; print $handle, "$address\n"; flock $handle, LOCK_UN or die "Flock failed: $!\n"; } }
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fork Me I need help
by neilwatson (Priest) on May 30, 2002 at 20:08 UTC |