Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by LanX (Archbishop)
on Nov 21, 2014 at 02:37 UTC ( #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
Node Status?
node history
Node Type: note [id://1107975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2019-12-12 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?