#!/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); open (BADADDR, ">badmails") || die; open (GOODADDR, ">goodmails") || die; OUTER: foreach $add (@adds){ $pm->start and next; foreach $x (@custom){ if ($add =~ m/$x/){ print BADADDR "$add\n"; #address is bad $pm->finish; } } #if email is invalid move on if (!defined(Email::Valid::Loose->address($add))){ print BADADDR "$add\n"; #address is bad $pm->finish; } #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) { print GOODADDR "$add\n"; #address is good }else{ print BADADDR "$add\n"; #address is bad } $pm->finish; } close (GOODADDR); close (BADADDR);
This code works. The only thing I noticed is that the parent will finish before some of the children (is that terminology correct?). If someone was impatient they would think the program is done when actaully it may need another minute to finish. Can this be prevented?
Neil Watson
watson-wilson.ca
In reply to Re: Fork Me I need help
by neilwatson
in thread Fork Me I need help
by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |