This is my first experiment with using fork. This program is a valid email checker much like this one. However, I am trying to speed it up by having the program check several addresses at once. Consider this code:

#!/usr/bin/perl -w #checks for valid email address #usage validemail <file containing email addresses> use warnings; use strict; use Email::Valid::Loose; use Net::DNS; use Parallel::ForkManager; my $pm=new Parallel::ForkManager(20); my $resolver=Net::DNS::Resolver->new(); my $addrfile = $ARGV[0]; my ($is_valid, $host, $ip, @goodaddr, @badaddr, $x, $record, @mx, $add +, @adds); #custom words that make emails invalid to you my @custom = qw( postmaster webmaster ); open (EMAILS, "$addrfile"); while (<EMAILS>){ $_ =~ s/\015//; chomp $_; push @adds, $_; } close (EMAILS); OUTER: foreach $add (@adds){ $pm->start and next; foreach $x (@custom){ if ($add =~ m/$x/){ push (@badaddr, $add); next OUTER; } } #if email is invalid move on if (!defined(Email::Valid::Loose->address($add))){ push (@badaddr, $add); next OUTER; } #if email is valid get hostname $is_valid = Email::Valid::Loose->address($add); if ($is_valid =~ m/\@(.*)$/) { $host = $1; } $is_valid=""; # perform dsn lookup to check domain @mx=mx($resolver, $host); if (@mx) { push (@goodaddr, $add); #address is good }else{ push (@badaddr, $add); #address is bad } $pm->finish; } #warning! I will delete existing files as I open them! open (BADADDR, ">badmails") || die; foreach $x (@badaddr){ print BADADDR "$x\n"; } close (BADADDR); open (GOODADDR, ">goodmails") || die; foreach $x (@goodaddr){ print GOODADDR "$x\n"; } close (GOODADDR);

The program seems to run ok but at the end it doesn't write anything to the goodmails or badmails files. The files are created but they're empty.

Can anyone help me?

Neil Watson
watson-wilson.ca


In reply to 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.