in reply to Testing multiple variables against the same criteria (IF statement)
You could do:
if( grep{ $_ == 1 } $var1, $var2, $var3, $var4 ) {
But that won't short-circuit -- ie. It will test all 4 variables every time -- and is really only beneficial if the vars are an array.
You might consider List::MoreUtils::any() which will short-circuit.
Personally, if there are only four variables and using an array doesn't work for you; I'd stick with your original statement.
|
|---|