Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIfference between "or" and "||"

Status
Not open for further replies.

dkyrtata

Programmer
Aug 13, 2010
107
CA
Why do the following boolean expressions return a different result? The first one returns 1 (true), which is correct.

Code:
$hh=23; 
$dd=32;

$bool1= ($hh>23) || ($dd>31);
$bool2= ($hh>23) or ($dd>31);

print "bool1=$bool1\n";
print "bool2=$bool2\n";
 
perlop said:
Binary "or" returns the logical disjunction of the two surrounding expressions. It's equivalent to || except for the very low precedence.
The second expression is doing this

[tt]($bool2= ($hh>23)) or ($dd>31);[/tt]

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Thanks, I confirmed it by enclosing the entire right side in brackets. Prior to Perl 5, there was only the "||" operator. The "or" was implemented in Perl 5, but I thought that it was just a synonym having the exact behavior.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top