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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Newb Question???

Status
Not open for further replies.

ridshack

MIS
Jul 16, 2008
2
US
Hey all,

Im trying to figure out how to do an if statement to match one of three vaules.

(START CODE)
my $value1 = 5
my $value2 = 6
my $value3 = 7

#Lost but Ill give an example

If ($random == $value1|$value2|$value3) #This didnt work. It always matched

If ($random == $value1 .. $value3) #This didnt work either.

(END CODE)

so any tips on how to acheive what I am trying would be nice.

what I have now is

(START CODE)
if ($random == $value1)
{
}
elsif ($random == $value2)
{
}
elsif ($random == $value3)
{
}
(END CODE)

This will work but I wanted to put a bunch of code the same code in the block if the condition was try and dindt want to include the code three times.

Thanks Rid

 
You were close
Code:
if ($random == $value1 || $random == $value2 || $random == $value3) {
    # do stuff
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top