http://www.perlmonks.org?node_id=1107975


in reply to Is the number before, in or after the interval? using spaceship operator <=>

already combining ($_ <=> $l) + ($_ <=> $r) gives you more details (abs == 1 when border hit) and you can easily derive any info needed.

DB<62> sub tst { print "$_: ", ($_ <=> $l) + ($_ <=> $r), "\n" } DB<63> ($l,$r)=(1,4) => (1, 4) DB<64> tst() for 0..6 0: -2 1: -1 2: 0 3: 0 4: 1 5: 2 6: 2

if you need to ignore borders try -($_ < $l) || ($_ > $r)

DB<79> sub leg { print "$_: ", -($_ < $l) || ($_ > $r) || 0, "\n" } DB<80> leg() for 0..6 0: -1 1: 0 2: 0 3: 0 4: 0 5: 1 6: 1

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)