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.9. Logical Operators

Perl has all of the necessary logical operators needed to work with Boolean (true/false) values. For example, it's often useful to combine logical tests by using the logical AND operator (&&) and the logical OR operator (||):

    if ($dessert{'cake'} && $dessert{'ice cream'}) {
      # Both are true
      print "Hooray! Cake and ice cream!\n";
    } elsif ($dessert{'cake'} || $dessert{'ice cream'}) {
      # At least one is true
      print "That's still good...\n";
    } else {
      # Neither is true - do nothing (we're sad)
    }


  

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