http://qs321.pair.com?node_id=11118832


in reply to Multiple numeric not or compare in if statement

Also worth mentioning: If your list of comparisons starts growing, grep is useful.

if (grep {$a == $_} (3,77,8)) {...} # If any of them match. if (!grep {$a == $_} (3,77,8)) {...} # If none of them match. if (0 == grep {$a == $_} (3,77,8)) {...} # Same as above but more expl +icit. if (3 == grep {$a != $_} (3,77,8)) {...} # Also if none of them match, + but maybe harder to follow.

For a list of three things, it may be more cognitive load to understand. But when the list grows to five or ten things, the grep becomes more palatable.


Dave