Do you know where your variables are? PerlMonks

### Re: Operator precedence

by ikegami (Pope)
 on Jan 13, 2013 at 21:21 UTC ( #1013131=note: print w/replies, xml ) Need Help??

There's no such thing as priority, and neither precedence nor associativity define the order in which stuff is evaluated. They determine what is an operand of what operator.

```apple && (banana || cherry)
apple:            LHS operand of &&
banana || cherry: RHS operand of &&
banana:           LHS operand of ||
cherry:           LHS operand of ||

(apple && banana) || cherry
apple && banana:  LHS operand of ||
apple:            LHS operand of &&
banana:           RHS operand of &&
cherry:           RHS operand of ||

Operand evaluation order is what controls the order in which stuff is evaluated.

In order to provide short-circuiting, && evaluates its LHS operand before its RHS. Same goes for ||.

Given

```apple && (banana || cherry)
apple:            LHS operand of &&
banana || cherry: RHS operand of &&
banana:           LHS operand of ||
cherry:           LHS operand of ||

apple must be evaluated before banana || cherry
banana must be evaluated before cherry

So we get:

1. apple
2. banana
3. cherry
4. ||
5. &&

Given

```(apple && banana) || cherry
apple && banana:  LHS operand of ||
apple:            LHS operand of &&
banana:           RHS operand of &&
cherry:           RHS operand of ||

apple && banana must be evaluated before cherry
apple must be evaluated before banana

So we get:

1. apple
2. banana
3. &&
4. cherry
5. ||

Replies are listed 'Best First'.
Re^2: Operator precedence
by muba (Priest) on Jan 18, 2013 at 22:43 UTC

It took me a good couple days to realise what you meant with "There's no such thing as priority, and neither precedence nor associativity define the order in which stuff is evaluated. They determine what is an operand of what operator."

But I get it now. Looking at it that clarifies a lot. Thank you.

Create A New User
Node Status?
node history
Node Type: note [id://1013131]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-02-25 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (314 votes). Check out past polls.

Notices?