You only think your code works. But what's going to happen if two children write at once?

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


In reply to Re: Fork Me I need help by Abigail-II
in thread Fork Me I need help by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.