laziness, impatience, and hubris | |
PerlMonks |
Re: Range check with unordered limitsby hexcoder (Curate) |
on Jul 13, 2022 at 06:44 UTC ( [id://11145463]=note: print w/replies, xml ) | Need Help?? |
Dear monks, thanks for your insights and extensions!
I did this one-liner as a fun task (because i was too lazy to detect min and max values beforehand) while working with integer values. I agree with syphilis and LanX that $inRange = (($a <=> $x) * ($b <=> $x)) <= 0; is the most canonical form, where <= emphasizes the inclusion of the limits while < would hint for the exclusion. My previous attempt was
$inRange = ($x > $a == $x < $b) || $x == $a || $x == $b; (inclusive)
which seemed less elegant, but the exclusive version might be faster. Cheers, Heiko
In Section
Cool Uses for Perl
|
|