If-Else Statements

Use else blocks for either/or constructions.

if ($a == $b) {
  print "a equals b\n";
  $a += $b;
} else {
  print "a does not equal b\n";
  die "Operation aborted!";
}

You can string tests together using elsif:

if ($a > 100) {
    die "a is too large\n";
} elsif ($a < 0) {
    die "a is too small\n";
} else {
    print "a is just right!\n";
}


<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Wed Oct 11 20:49:00 EDT 2000