Just a quick question
printf("%d", 99 || 44) prints "1" in C
print 99 || 44 prints "99" in perl
There are two different kinds of evaluation. Does each one have a name?
edit: i’m interested to know how this Perl evaluation is commonly called when compared to C. When you say “C example is X, and perl example is not X, but Y” which words would you use for X and Y. “short circuit” is not what i’m looking for.
The C version uses || as the logical OR between the two values. Both 44 and 99 evaluate to
truein C as they are not0, so the result of an OR between them returns1(AKAtruein 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. Since99is 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)