Associativity | Operator | Prece- dence |
Meaning |
left | ( ) | 0 | terms (includes: variables, quote-like operators, expressions in parenthesis, any function whose arguments are parenthesized |
left | print(), chdir() |
0 | list operators. In the absence of parenthesis, the precedence of list operators such as "print", "sort", "chmod" is either very high or very low depending on whether you are looking at the left side or the right side of the operator. For example, in @ary=(1,3, sort 4, 2); the commas on the right of the sort are evaluated before the sort, but the commas on the left are evaluated after. In other words, list operators tend to gobble up all arguments that follow, and then act like a simple term with regard to the preceding expression. |
left | -> | ? | Infix dereference or field selector as in C/C++. If the right side is either a "[...]", "{...}", or a"(...)" subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. |
nonassoc | ++ -- |
? | Auto-increment (++), auto-decrement (--). If placed before the variable the increment/decrement of the variable takes place before returning the value, and if placed after, increment/decrement the variable after returning the value. |
right | ** | ? | Exponentiation |
right | ! ~ \ unary + unary - |
? | boolean or logical: not (2) bitwise: not (1) ??? unary plus unary minus |
left | =~ !~ |
? | True if left string matches with regular expression on right. True if left string does not have a match with regular expression on right. (Note.A: Literal string in the regex on right can be replaced with a variable: /$var/) (Note.B: If matching against "$_", the "$_ =~" can be omitted: $_ = "Hello World"; print "ok" if /World/;) |
left | * / % x |
? | multiply divide modulo string repeat |
left | + - . |
? | add subtract string concatenate |
left | << >> |
? | shift left shift right |
nonassoc | ??? | ? | named unary operators |
nonassoc | < > <= >= lt gt le ge |
? | arithmetic compare string compare |
nonassoc | == != <=> eq ne cmp |
? | arithmetic: equal, not equal, compare string: equal, not equal, compare |
left | & | ^ | ? | bitwise: and, or, xor (1) |
left | && || | ? | boolean or logical: and, or (2) |
nonassoc | .. ... |
? | range (3) |
right | ? : | ? | conditional, e.g.: test_expr?true_expr:false_expr |
right | = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= |
? | assignment (with operation)
$var OP= $expr; # is same as:Be careful of post/pre increment/decrement operators on left side in terms of number of times executed! |
left | , => |
? | comma (4) key value separator in hash list (comma synonym) |
nonassoc | ( , , , ) | ? | list operators (rightward) |
right | not | ? | boolean or logical (2) |
left | and or xor | ? | boolean or logical (2) |