Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

10.5. The elsif Clause

Every so often, you may need to check a number of conditional expressions, one after another, to see which one of them is true. This can be done with the if control structure's elsif clause, as in this example:

    if ( ! defined $dino) {
      print "The value is undef.\n";
    } elsif ($dino =~ /^-?\d+\.?$/) {
      print "The value is an integer.\n";
    } elsif ($dino =~ /^-?\d*\.\d+$/) {
      print "The value is a _simple_ floating-point number.\n";
    } elsif ($dino eq '') {
      print "The value is the empty string.\n";
    } else {
      print "The value is the string '$dino'.\n";
    }


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial