< Perl Tutorial

Perl operator precedence

← Previous Next →

Perl Operator Precedence

Some operators have more precedence than others and hence they will be performed earlier than certain other operators if they are used in the same experession. Associativity determines how operators that have the same precedence are evaluated (where our choices are left-to-right, right-to-left, or nonassociative for those operators where order of evaluation is either not important, not guaranteed, or not even possible). Operators of a higher precedence (evaluated first) are higher up in the table than those of a lower precedence.

The following table elists the operators according to their precedence.

 Operator Associativity   Description
 ->  left  Dereference operator
 ++, --  non  Increment and decrement
 **  right  Exponent
 !,~,\,+,-  right  Logical not, bitwise not,  reference, unary +, unary -
 =~, !~  left  Pattern Matching
 *,/,%  left  Multiplication, Division, Modulus
 +,-,.  left  Add, Subtract, String concatenate
 <<, >>  left  Bitwise left shift and right shift
 unary operators  non  Function-like operators
<,>,<=,>=,lt,gt,le,ge non Tests
==, !=, <=>, eq, ne, cmp non Tests
& left Bitwise AND
|,^ left Bitwise OP,XOR
&& left Logical AND
|| left Logical OR
=,+=,-=,*=,/= rigth Assignment operators
,, => left Comma operators
list operators non list operators used in list
not right Logical NOT
and right Logical AND
or, xor left Logical OR, XOR
← Previous Next →