Is there a statement that performs a simple T/F or 0/1 logical conjunction operation, returning either boolean T/F or binary or integer representations of 0 or 1 as the exclusive output?
The &&
and and
operators, rather than returning T/F (boolean) or 0/1 (binary) return whatever value is provided as the second argument to the operator assuming both arguments are "true" (e.g., perl -e '$x=(3 && 2); print $x,"\n"'
yields a value of 2; changing the statement to perl -e '$x=(3 && 4); print $x,"\n"' yields a value of 4). I am trying to find an operator that does not require either division by the final argument or an additional if
statement to return strictly a 0 or 1.
My reason for seeking such an operator is to increment a counter by 0 or 1 based on the logical conjunction of two operands, and I prefer the concision of a statement such as $counter += ($x && $y)
, as opposed to the alternatives (e.g., if($x && $y) counter++
or $counter += ($x && $y)/$y
).