neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fork Me I need help
by Abigail-II (Bishop) on May 30, 2002 at 16:13 UTC | |
|
Re: Fork Me I need help
by Molt (Chaplain) on May 30, 2002 at 16:14 UTC | |
|
Re: Fork Me I need help
by neilwatson (Priest) on May 30, 2002 at 17:27 UTC | |
by Abigail-II (Bishop) on May 30, 2002 at 18:11 UTC | |
by neilwatson (Priest) on May 30, 2002 at 20:08 UTC |