Sogalei has asked for the wisdom of the Perl Monks concerning the following question:
Question: Logical operators giving wrong results. The results are only correct when $a is true and $b is false. Any advice to fix this?
$a = false; $b = true; print "Value of \$a = $a and value of \$b = $b\n"; $c = ($a and $b); print "Value of \$a and \$b = $c\n"; $c = ($a && $b); print "Value of \$a && \$b = $c\n"; $c = ($a or $b); print "Value of \$a or \$b = $c\n"; $c = ($a || $b); print "Value of \$a || \$b = $c\n"; $a = 0; $c = not($a); print "Value of not(\$a)= $c\n"; ***Result*** Value of $a = false and value of $b = true Value of $a and $b = true Value of $a && $b = true Value of $a or $b = false Value of $a || $b = false Value of not($a)= 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl logical operators
by choroba (Cardinal) on Jul 18, 2018 at 06:47 UTC | |
|
Re: Perl logical operators
by tobyink (Canon) on Jul 18, 2018 at 07:23 UTC | |
by tweetiepooh (Hermit) on Jul 10, 2019 at 13:38 UTC | |
by choroba (Cardinal) on Jul 10, 2019 at 13:49 UTC | |
by hippo (Archbishop) on Jul 10, 2019 at 13:48 UTC | |
|
Re: Perl logical operators
by AnomalousMonk (Archbishop) on Jul 18, 2018 at 13:02 UTC | |
|
Re: Perl logical operators
by ikegami (Patriarch) on Jul 18, 2018 at 11:19 UTC | |
by Anonymous Monk on Jul 18, 2018 at 12:32 UTC | |
by hippo (Archbishop) on Jul 18, 2018 at 12:40 UTC | |
by roboticus (Chancellor) on Jul 18, 2018 at 17:32 UTC | |
by Your Mother (Archbishop) on Jul 18, 2018 at 18:51 UTC | |
| |
by Anonymous Monk on Jul 19, 2018 at 09:21 UTC | |
| |
by haukex (Archbishop) on Jul 18, 2018 at 18:06 UTC |