Hi Folks
I've got a variable in my Perl script called $config. I want to ensure that it's value is equal to either 1, 2, or 3. What I'd really like to do is this:
IF $config IS NOT EQUAL TO 1, 2 OR 3
print "Variable is not valid!";
I can't seem to figure out a way to do this in two lines though. The best I can manage is:
if ($config == 1) {
print "Variable is equal to 1";
} elsif ($config == 2) {
print "Variable is equal to 2";
} elsif ($config == 3) {
print "Variable is equal to 3";
} else {
print "Variable is not valid!";
}
Is there any other way I can do this or is my code above the best solution?
Cheers,
Kenny.
I've got a variable in my Perl script called $config. I want to ensure that it's value is equal to either 1, 2, or 3. What I'd really like to do is this:
IF $config IS NOT EQUAL TO 1, 2 OR 3
print "Variable is not valid!";
I can't seem to figure out a way to do this in two lines though. The best I can manage is:
if ($config == 1) {
print "Variable is equal to 1";
} elsif ($config == 2) {
print "Variable is equal to 2";
} elsif ($config == 3) {
print "Variable is equal to 3";
} else {
print "Variable is not valid!";
}
Is there any other way I can do this or is my code above the best solution?
Cheers,
Kenny.