Hi, I want to check whether a variable is equal to any one of the three (or even more) values. For example, I want to check whether $country equals to India, America, Germany or Austria. When I used if statement, in the following way, I did not get the output.
if($country eq (India|America|Germany|Austria)) { print "True"; }
Alternatively, if I use it the following way, it is working fine. But, this will practically be impossible for the number of options I am going to use in the script.
if($country eq "India"|$country eq "America"|$country eq "Germany"|$co +untry eq "Austria") { print "True"; }
If I use a array to store all the possible options, and check whether the variable $country matches to any of the elements, that too is working fine, but I am sure there will be a way of doing this in a simplified manner using if statement or any other conditional loops. Though it sounds simple, I have scratched my head enough. Can anyone help me please..
In reply to Using the 'if' statement... by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |