--------------------------------------------------------- \$this && \$that | If \$this is true, return \$that, \$this and \$that | else return \$this. -----------------+--------------------------------------- \$this || \$that | If \$this is true, return \$this, \$this or \$that | else return \$that. --------------------------------------------------------- ##```## my (\$first, \$second) = ( 1, 1 ); print "Truth\n" if \$first++ && \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ Truth First: 2 Second: 2 ##``````## my (\$first, \$second) = ( 1, 0 ); print "Truth\n" if \$first++ && \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ First: 2 Second: 1 # Note: Both are evaluated because the first one is # true. But "Truth" isn't printed, because only one # of the two expressions evaluated "true". ##``````## my (\$first, \$second) = ( 0, 1 ); print "Truth\n" if \$first++ && \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ First: 1 Second: 1 # \$second didn't get incremented because the # evaluation stopped when \$first evaluated false. ##``````## my (\$first, \$second) = ( 0, 0 ); print "Truth\n" if \$first++ && \$second++; print "First: \$first\nSecond: \$second\n"; __Output__ First: 1 Second: 0 # \$first was evaluated for truth. It was false, # so \$second didn't get evaluated. ##``````## my (\$first, \$second) = ( 1, 1 ); print "Truth\n" if \$first++ || \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ Truth First: 2 Second: 1 # Since \$first is true, no need to evaluate \$second; # we already know that the 'or' expression is true. ##``````## my (\$first, \$second) = ( 1, 0 ); print "Truth\n" if \$first++ || \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ Truth First: 2 Second: 0 # Again, \$second is never evaluated because \$first # is true, and that's good enough for ||. ##``````## my (\$first, \$second) = ( 0, 1 ); print "Truth\n" if \$first++ || \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ Truth First: 1 Second: 2 # Both sides got evaluated because since \$first was # false it was necessary to evaluate \$second to # determine if truth exists (it does). ##``````## my (\$first, \$second) = ( 0, 0 ); print "Truth\n" if \$first++ || \$second++; print "First: \$first\nSecond: \$second\n"; __OUTPUT__ First: 1 Second: 1 # There is no truth. Both expressions were # evaluated to find it. ##``````## open( FILE, "## local \$_ = 'xyz'; SWITCH: { /^abc/ && do { \$abc = 1; last SWITCH; }; /^def/ && do { \$def = 1; last SWITCH; }; /^xyz/ && do { \$xyz = 1; last SWITCH; }; \$default = 1; } #### if ( \$this && \$that && \$other ) { print "Truth\n"; } #### my \$client = \$ENV{USER_HOST} || \$ENV{USER_ADDR} || "UNKNOWN"; #### my @sorted = sort { uc(\$a) cmp uc(\$b) || \$a cmp \$b } @unsorted; #### my @list = ( { 'Name' => "Pete", 'Age' => 32 }, { 'Name' => "Pete", 'Age' => 55 } ); my @sorted = sort { \$a->{'Name'} cmp \$b->{'Name'} || \$a->{'Age' } <=> \$b->{'Age' } } @list; #### open ( FILE, "```