Webmaster in a Nutshell

Previous Chapter 15
Perl Quick Reference
Next
 

15.4 Operators

**      

Exponentiation

+ - * /

Addition, subtraction, multiplication, division

%      

Modulo division

& | ^  

Bitwise AND, bitwise OR, bitwise exclusive OR

>> <<    

Bitwise shift right, bitwise shift left

|| &&    

Logical OR, logical AND

.      

Concatenation of two strings

x      

Returns a string or array consisting of the left operand (an array or a string) repeated the number of times specified by the right operand.

All of the above operators have an associated assignment operator, e.g., .=

->  

Dereference operator

\  

Reference (unary)

! ~

Negation (unary), bitwise complement (unary)

++ --

Auto-increment (magical on strings), auto-decrement

== !=

Numeric equality, inequality

eq ne String equality, inequality
< >

Numeric less than, greater than

lt gt String less than, greater than
<= >=

Numeric less (greater) than or equal to

le ge

String less (greater) than or equal to

<=> cmp

Numeric (string) compare. Returns -1, 0, or 1.

=~ !~

Search pattern, substitution, or translation (negated)

..  

Range (scalar context) or enumeration (array context)

? :  

Alternation (if-then-else) operator

,  

Comma operator, also list element separator. You can also use =>

not  

Low-precedence negation

and  

Low-precedence AND

or xor

Low-precedence OR, exclusive OR

All Perl functions can be used as list operators, in which case they have either very high or very low precedence, depending on whether you look at the left or the right side of the operator. Only the operators not, and, or, and xor have lower precedence.

A "list" is a list of expressions, variables, or lists. An array variable or an array slice may always be used instead of a list.

Parentheses can be added around the parameter lists to avoid precedence problems.


Previous Home Next
Variables Book Index Statements

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell