Perl Cheat Sheet Page 6

ADVERTISEMENT

5. Operators and precedence
Perl operators have the following associativity and precedence, listed from highest
precedence to lowest.
Assoc Operators
Description
left
terms and list operators
See below.
left
Infix dereference operator.
->
++
Auto-increment (magical on strings).
Auto-decrement.
--
right **
Exponentiation.
right \
Reference to an object (unary).
right !
Unary negation, bitwise complement.
˜
right +
Unary plus, minus.
-
left
Binds a scalar expression to a pattern match.
left
Same, but negates the result.
left
*
/
%
x
Multiplication, division, modulo, repetition.
left
Addition, subtraction, concatenation.
+
-
.
left
Bitwise shift right, bitwise shift left.
>>
<<
named unary operators
E.g.
,
, -f , -M .
sin
chdir
Numerical relational operators.
<
>
<=
>=
String relational operators.
lt gt le ge
Numerical equal, not equal, compare.
==
!=
<=>
eq ne cmp
Stringwise equal, not equal, compare.
Compare operators return -1 (less), 0 (equal)
or 1 (greater).
left
Bitwise AND.
&
left
Bitwise OR, exclusive OR.
|
ˆ
left
&&
Logical AND.
left
||
Logical OR.
In scalar context, range operator.
..
In array context, enumeration.
right ?:
Conditional (if ? then : else) operator.
right =
*= etc. Assignment operators.
+=
-=
left
Comma operator, also list element separator.
,
left
Same, enforces the left operand to be a string.
=>
list operators (rightward) See below.
right
Low precedence logical NOT.
not
left
and
Low precedence logical AND.
left
or xor
Low precedence logical OR, exclusive OR.
Parentheses can be used to group an expression into a term.
A ‘list’ is a list of expressions, variables or lists, separated by commas. An array
variable or an array slice may always be used instead of a list.
All Perl functions can be used as list operators, in which case they have very high
or very low precedence, depending on whether you look at the left side of the
operator or at the right side of the operator.
Parentheses can be added around the parameter lists to avoid precedence problems.
The logical operators do not evaluate the right operand if the result is already
known after evaluation of the left operand.
6

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education