Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by LanX (Saint)
on Nov 21, 2014 at 02:37 UTC ( [id://1107975]=note: print w/replies, xml ) Need Help??


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 ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-24 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found