develooper Front page | perl.perl5.porters | Postings from February 2020

Re: chained comparisons

Thread Previous | Thread Next
Zefram via perl5-porters
February 7, 2020 08:59
Re: chained comparisons
Message ID:
demerphq wrote:
>Er, then my bad. What did I mess up?

You show "<" chaining with "==".  They're at different precedence levels,
so don't chain together.  "$a < $b == $c" is already legal Perl, meaning
"($a < $b) == $c".  I think the intent (in C, where this precedence comes
from) is that the equality operators can function as logical connectives
EQV and XOR.

The bit about FETCH methods is unclear and possibly wrong.  It's firstly
confusing because it's mixed up with an example concerning an explicit
call to an expensive function, which is a different kind of expensive
computation.  The real unclarity is that it doesn't say in which version
of the code the FETCH method would be called only once.  The ordering of
the text seems to imply that the chained version would call it only once
and the unchained version with explicit temporary would call it twice.
In fact the reality is the reverse: the chained version may call FETCH
twice (it's done by each comparison op), but the unchained version with
explicit temporary calls FETCH exactly once (at the assignment to the

There's also a typo "exmaple".

Stylistically, if the discussion of chaining is to be so extensive then
I think it doesn't belong in the section on the relational operators.
It should instead go with the general discussion of associativity.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About