Nov 1, 2003 #1 nfaber Technical User Joined Oct 22, 2001 Messages 446 Location US Hello all. I am trying to use logical ors in an if statement that does not seem to be working. Here is my sample code: if ($day = 24||25||26||27||28||29||30) { do something; }else{ do something else; } How do you use multiple ors? Thanks
Hello all. I am trying to use logical ors in an if statement that does not seem to be working. Here is my sample code: if ($day = 24||25||26||27||28||29||30) { do something; }else{ do something else; } How do you use multiple ors? Thanks
Nov 1, 2003 1 #2 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB Well for numeric values at least, it would be Code: if ( $day >= 24 && $day <= 30 ) -- http://www.catb.org/~esr/faqs/smart-questions.html Upvote 0 Downvote
Well for numeric values at least, it would be Code: if ( $day >= 24 && $day <= 30 ) -- http://www.catb.org/~esr/faqs/smart-questions.html
Nov 2, 2003 #3 dchoulette Programmer Joined Jun 25, 2002 Messages 245 Location FR If the values were not continuous, you could use: Code: if (($day == 24) || ($day == 25) || ... || ($day == 30) or you could test as a string: Code: if ($day =~ m/^(24|25|26|27|28|29|30)$/) "When all else has failed, read the manuals." Denis Upvote 0 Downvote
If the values were not continuous, you could use: Code: if (($day == 24) || ($day == 25) || ... || ($day == 30) or you could test as a string: Code: if ($day =~ m/^(24|25|26|27|28|29|30)$/) "When all else has failed, read the manuals." Denis
Nov 2, 2003 #4 icrf Programmer Joined Dec 4, 2001 Messages 1,300 Location US For a smallish list of possible values like that, I'd probably grep it: Code: if(grep $day == $_, 24..30) ---------------------------------------------------------------------------------- ...but I'm just a C man trying to see the light Upvote 0 Downvote
For a smallish list of possible values like that, I'd probably grep it: Code: if(grep $day == $_, 24..30) ---------------------------------------------------------------------------------- ...but I'm just a C man trying to see the light