in reply to long if statements... What's the best way?

You can try using an if else combination.
if ($var eq "a") {
print "Test number one";
}
elsif ($var eq "b") {
print "test two";
}
else {
print "test three";
}
  • Comment on Re: long if statements... What's the best way?

Replies are listed 'Best First'.
Re^2: long if statements... What's the best way?
by kyle (Abbot) on Apr 02, 2008 at 16:30 UTC

    Using the double pipe ("||") already short circuits testing. In this expression:

    ( $var eq 'a' || $var eq 'b' || $var eq 'c' )

    ...If it turns out that $var eq 'a', the other two conditions are not checked. If $var eq 'b', then only the first two conditions will be checked and not the third.

    Moreover, it does not appear that the OP wants to take different actions for the different values, so having separate blocks for each value found doesn't make sense.