As long as the operators look the same, their purpose is actually different.
From perldoc perlop :
Binary "||" performs a short circuit logical operation OR. That is, if the left operand is right, the right operand is not even evaluated.
Compared with:
Binary "|" returns its operands ORed little by little.
Purpose || is to come up with an answer to "is x || y true or false?" while the goal is bitwise or - | - come up with a product (?) from operands or something like "what is the result of x | y ?"
Since the only interesting two results from || are true or false, the operator can (and is) short-term, thereby causing this effect.
In the first statement: (0 | 2) = 2, (2 | 4) = 6
In the second statement: (0 || 2) = 2, (2 || ...) = 2
Interestingly, bitwise or sets logical values ββinside a binary number. Adding a true or false value to a position in the binary representation of a number.
0000 | 0010 = 0010 0010 | 0100 = 0110 0110 | 0001 = 0111 0111 | 0001 = 0111
This is very convenient for storing several logical values ββin one number, which can be checked with & ( bitwise AND ).
0101 & 0100 = 0100 (true) 0101 & 0010 = 0000 (false)
There are 10 kinds of people: those who understand binary numbers, and those who do not.
source share