Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Testing multiple variables against the same criteria (IF statement)

by BrowserUk (Patriarch)
on Sep 05, 2016 at 17:57 UTC ( [id://1171210]=note: print w/replies, xml ) Need Help??


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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1171210]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found