Gossamer Forum
Home : General : Perl Programming :

How to exit a "foreach" loop early?

Quote Reply
How to exit a "foreach" loop early?
I'm doing a little mod of DBMan to check for unacceptable words. What I have so far is

Quote:
foreach $dirty_word (@dirty_words) {
if (lc($in{$col}) =~ /$dirty_word/) {
push(@input_err, "$col (Includes a banned word.");
}
}

As soon as it comes up with one unacceptable word, there's no point in checking for more. How do I exit the loop early?

Thanks much!



------------------
JPD
Quote Reply
Re: How to exit a "foreach" loop early? In reply to
DIRTY: foreach $dirty_word (@dirty_words) {
if (lc($in{$col}) =~ /$dirty_word/) {
push(@input_err, "$col (Includes a banned word.");
last DIRTY;
}
}

Should do it for ya!

--Mark

------------------
You can reach my by ICQ at UIN #8602162

Quote Reply
Re: How to exit a "foreach" loop early? In reply to
Thanks Mark!