Fellow monks,
I'm having an issue that I can't seem to figure out. Below is my subroutine. It's purpose is to match an email address from a whois query and have a list of email addresses to ignore. The ignore regex seems to work fine, but when an email is ignored, Perl still appears to be assigning the value to undef because I'm getting this error when running the script:
Use of uninitialized value in split at ./temp.pl line 258.
Use of uninitialized value in string at ./temp.pl line 290.
Use of uninitialized value in concatenation (.) at ./temp.pl line 290.
Can't use an undefined value as a symbol reference at /usr/lib/perl5/s
+ite_perl/5.6.0/Mail/Sender.pm line 832.
It appears to be dying because
Mail::Sender is being passed an undefined value. Any suggestions on how to code this properly? Also, does my ignore regex look ok?
sub match {
my (@newemails, @emails);
# Email addresses to ignore
my $ignore = qr(([-.\w]+\@apnic\.[com|net]) | ([-.\w]+\@uu\.net) | (
+hostmaster\@nic\.or\.kr) | ([-.\w]+\@[RIPE\.NET|ripe\.net]) |
([-.\w]+\@iana\.org) | (NOC\@SPRINT\.NET);
# Save all emails from whois query to an array
@emails = $result =~ m/([-.\w]+\@[-.\w]+)/g;
my %saw;
@emails = grep(!$saw{$_}++, @emails); #remove duplicates
# Remove all ignore emails and save to new array
foreach (@emails){
next if $_ =~ $ignore;
push(@newemails, $_);
}
#Save the email and domain portion to separate vars
my ($email, $domain) = split(/\@/, $newemails[0]);
#Run the mail sub for each email address
&mail($newemails[0], $domain);
}
*Note: I know my regex will not match 100% of emails, but I'm happy wi
+th 75 - 90%. It's been working out well so far.
Thanks,
Dru
Another satisfied monk.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.