Increment and Decrement Operators

The ++ and -- operators are used with a variable to increment or decrement that variable by 1 (that is, to add or subtract 1). And as with C, both operators can be used either in prefix fashion (before the variable, ++$x) or in postfix (after the variable, $x++). Depending on the usage, the variable will be incremented or decremented before or after it's used.

If your reaction to the previous paragraph is “Huh?”, here's a wordier explanation. The ++ and -- operators are used with scalar variables to increment or decrement the value of that variable by 1, sort of an even shorter shorthand to the += or -= operators. In addition, both operators can be used before the variable reference—called prefix notation, like ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.