in reply to Is X in my array?

So, my question: is there anything wrong with this?

If your target array is only going to contain single-character strings, then no. But if the strings get larger, you risk matching "food" when you're seeking "foo". And if the strings ever contain spaces, you risk more false positives.

Better, I think, to use grep.

Replies are listed 'Best First'.
Re: Re: Is X in my array?
by Not_a_Number (Prior) on Jun 17, 2003 at 18:33 UTC

    ...if the strings get larger, you risk matching "food" with when you're seeking "foo". And if the strings ever contain spaces, you risk more false positives.

    Right, thanks. I should have thought of that myself. In other words, this 'idiom' is highly dangerous.

    dave