I can't run this code to find the origin of the error, so instead i present you with some strategies for finding this bug.

I would pull out the old Data::Dumper module and use it to find where that/those undef's are. You say that it happens duing the ignore code, if that's true, than the undef's where already in @emails. grep shouldn't return an undef (in your context), so i am guessing that the undef's are creeping in during the 'regex split' or from the split just before the call to &mail().

Getting rid of the undef's is best done by not putting them in, but you can always bypass them like so:

foreach (@emails){ next unless $_; next if $_ =~ $ignore; push(@newemails, $_); }

Not the best way, that solution doesn't solve the problem, just the symptom. Use Data::Dumper on @emails once before you do anything with it, and once after your 'regex split', like so:

print Dumper \@emails;

The error could be in this line:

my ($email, $domain) = split(/\@/, $newemails[0]);

Print out the contents to see what is really there. This is one way (probablly not the best) to avoid calling &mail():

&mail($newemails[0], $domain) if $newemails[0] and $domain;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: How not to pass undef variables by jeffa
in thread How not to pass undef variables by dru145

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.