Scalar Variables and Operators
Operator Precedence and Associativity
- Operator Associativity refers to what is resolved first
when deciding what to operate on.
- Right Associativity results in implied parenthesis to
the right.
- Left Associativity results in implied parenthesis to
the left.
- Right Associativity Example: in 5 ** 6 ** 7
, an equivalent operation would be (5 ** (6 ** 7))
because the ** operator is right associative.
- Left Associativity Example: in 5 / 6 / 7 ,
an equivalent operation would be ((5 / 6) / 7)) because
the / operator is left associative.
- Yes. It is terrible programming practice to allow these to
default implicitly. You should always us parenthesis to explicitly
define the order of operations.
- Precedence refers to which operations will be performed
in what order. Higher precedence operations are performed before lower
precedence operations.
- With parenthesis, the innermost parenthesis are
completely evaluated first, and it progresses outward. This
explicitly and clearly overrides the hidden implicit precedence
rules.
- man perlop will give a complete
description of operator precedence and associativity.
Back to Syllabus
Previous: Scalar Operators for Strings
Next: Converting between numbers and strings