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

Re: chained comparisons

Thread Previous | Thread Next
Zefram via perl5-porters
April 28, 2020 15:20
Re: chained comparisons
Message ID:
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().


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