The C version uses || as the logical OR between the two values. Both 44 and 99 evaluate to true
in C as they are not 0
, so the result of an OR between them returns 1
(AKA true
in C)
In that particular perl snippet, || is the null-coalescing operator, an binary which evaluates to the second argument if the first is null, otherwise evaluating to the first argument. Since 99
is the first argument and not null, it gets returned and printed.
EDIT: Thanks Evan for the clafication: The || operator in perl is not the null-coalescing operator, it returns the RHS if the LHS evaluates to false, other wise returning the LHS. //
is the "proper" null-coalescing operator.
Here's the list of values in perl that evaluate to false (from wikipedia)
$false = 0; # the number zero
$false = 0.0; # the number zero as a float
$false = 0b0; # the number zero in binary
$false = 0x0; # the number zero in hexadecimal
$false = '0'; # the string zero
$false = ""; # the empty string
$false = undef; # the return value from undef
$false = 2-3+1 # computes to 0 which is converted to "0" so it is false