Table 274 Perl Arithmetic Operators

Operator

Purpose

x**y

Raises x to the y power (same as x^y)

x%y

Calculates the remainder of x/y

x+y

Adds x to y

x-y

Subtracts y from x

x*y

Multiplies x times y

x/y

Divides x by y

-y

Negates y (switches the sign of y); also known as the unary minus

++y

Increments y by 1 and uses value (prefix increment)

y++

Uses value of y and then increments by 1 (postfix increment)

-- y

Decrements y by 1 and uses value (prefix decrement)

y--

Uses value of y and then decrements by 1 (postfix decrement)

x=y

Assigns value of y to x. Perl also supports operator-assignment operators (+=,

You can also use comparison operators (such as == or <) and compound pattern operators (&&, ||, and !) in arithmetic statements. They evaluate to the value 0 for false and 1 for true.

Was this article helpful?

0 0

Post a comment