Two approaches that I have observed:
- Put the desired elements into a hash, with a value (say...) of 1, then look for each value. If it’s there, the result will be True, otherwise (undef) it will be False.
-
Use a regex, e.g. if ($foo =~ /^(12|345|67)$/) ... Notice how the ^ and $ serve to bind the match to both the beginning and the end of the string, hence to “the value of the entire string.”
-
Use a sub. You can get as messy as you like in a sub, so to speak, because you only get messy once.
As far as I am concerned, the number-one priority is that the logic should be crystal clear, as well as maintainable.