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

Re: chained comparisons

Thread Previous | Thread Next
From:
Zefram via perl5-porters
Date:
April 28, 2020 15:20
Subject:
Re: chained comparisons
Message ID:
20200428152031.zn5nljuvngqzjx7y@fysh.org
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.

For situations like this it might be nice to have an explicit
value-copying identity op.  This can easily be done in a CPAN module.
It'd be presented as an identity function, but with call checker magic
compiling it down to a custom op that just does a newSVsv().

-zefram

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