Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Re: Operator Precedence

by ariels (Curate)
on Jul 22, 2001 at 18:13 UTC ( #98818=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Operator Precedence
in thread Operator Precedence

Precedence is not the issue in comparing
$x >= $x_min and $x <= $x_max and $y >= $y_min and $y <= $y_max
with
($x >= $x_min and $x <= $x_max) and ($y >= $y_min and $y <= $y_max)
Neither will work if and has higher precedence than &lt;= and &gt;=!

The issue with the extra brackets here is to add a structure to the code that simplifies understanding. Instead of having to understand 4 independent logical tests, I have to understand 2 logical tests, then combine them. And once I've worked out the first test is "$x is between $x_min and $x_max", the second test is much easier to work out.

An alternative way to produce the division is simply by using a line break:

$x >= $x_min and $x <= $x_max and $y >= $y_min and $y <= $y_max
also makes the analogy easier.

In any case, a much nicer way to write an interval test (if you're worried about readability) is to put $x on the inside, and keep all comparisons using the same direction:

$x_min <= $x and $x <= $x_max and $y_min <= $y and $y <= $y_max

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-03-26 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (63 votes). Check out past polls.

    Notices?