Arithmetic Operators

Operators are not the most thrilling of Perl topics to read about, but you need them to build expressions. Perl has a fairly robust set of operators for building expressions with scalars. You'll learn about some of these operators today, and most of the remainder of them tomorrow in Day 3, “More Scalar Data and Operators.”

We'll start with the arithmetic operators, which perform arithmetic operations on numeric data. Strings are converted to numbers as needed. Perl includes the operators shown in Table 2.2 for basic arithmetic operations, with the operands usually appearing on either side of the operator, as you'd expect.

Table 2.2. Arithmetic Operators
Operator What it Does For Example Results In
+ Addition 3 + 4 7
- Subtraction ...

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.