Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to test if multiple conditions exist 1

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top