Assignment Operators

Perl recognizes the following operators for assigning a value to a variable:

=    **=    +=    *=    &=    <<=    &&=
-=    /=    |=    >>=   ||=    .=     %=
^=    x=

Each operator requires a variable on the left side and an expression on the right side. For the simple assignment operator, =, the value of the expression is stored in the designated variable. For the other operators, Perl evaluates the expression:

$var OP= $value

as if it was written:

$var = $var OP $value

except that $var is evaluated only once. For example:

$a += 2;    # Same as $a = $a + 2

Get Perl in a Nutshell, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.