Perl-Sensitive Sunglasses | |
PerlMonks |
Re: How not to pass undef variablesby count0 (Friar) |
on Jan 10, 2002 at 22:02 UTC ( [id://137787]=note: print w/replies, xml ) | Need Help?? |
From the very first assignment to @emails, you have no idea how many, if any, elements it has. A good general rule to follow is that when you don't know if there is a value, test it! ;) The @emails = grep... statement doesn't need any input, so you're safe there. The foreach... doesn't need @emails to have anything in it, so again, that's ok. When you get down to the split(), you have a problem. If @newemails has no elements in it.. perl will complain, and $email and $domain will be undefined. The simplest way to deal with this situation is to test if @newemails has any elements. Wrap any code that depends on it containing something, into that test:
In Section
Seekers of Perl Wisdom
|
|