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

Re: chained comparisons

Thread Previous | Thread Next
From:
Dan Book
Date:
April 28, 2020 19:21
Subject:
Re: chained comparisons
Message ID:
CABMkAVXU9aP87kBLo=AwE8afU+fHYyTue3S_TS6ijey8MGhVOA@mail.gmail.com
On Tue, Apr 28, 2020 at 11:20 AM Zefram via perl5-porters <
perl5-porters@perl.org> wrote:

> David Nicol wrote:
> >does turning the tied thing into an expression by applying a no-op to it
> in
> >perl code prevent the second fetch?
> >
> >lower <= 0+$tied_thing < upper
>
> Yes.  In that case the tied value is fetched by the addition op, which
> only runs once, and the two comparisons will be applied to the result
> of the addition, which (unless there's some funny overloading going on)
> will be non-magical.
>

I've opened https://github.com/Perl/perl5/pull/17760 to hopefully provide
this clearer explanation in the docs. Other than explaining that better,
this functionality seems correct to me.

-Dan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About