Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Another quick question! Is there a shorthand way to test multiple variables against the same criteria within an IF statement where only 1 of the variables needs to match for it trigger the statement? For example, I would normally use:
if ($var1 == 1 || $var2 == 1 || $var3 == 1 || $var4 == 1) {To do something like this - but it's quite longwinded. What i'm after is a shorter way to test whether any of those variables == 1.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing multiple variables against the same criteria (IF statement)
by NetWallah (Canon) on Sep 05, 2016 at 17:56 UTC | |
|
Re: Testing multiple variables against the same criteria (IF statement)
by BrowserUk (Patriarch) on Sep 05, 2016 at 17:57 UTC | |
|
Re: Testing multiple variables against the same criteria (IF statement)
by shmem (Chancellor) on Sep 05, 2016 at 21:36 UTC | |
by AnomalousMonk (Archbishop) on Sep 05, 2016 at 22:44 UTC | |
|
Re: Testing multiple variables against the same criteria (IF statement)
by haukex (Archbishop) on Sep 05, 2016 at 18:32 UTC | |
|
Re: Testing multiple variables against the same criteria (IF statement)
by hippo (Archbishop) on Sep 05, 2016 at 20:40 UTC |