For more information on how operators work, consult the perlop documentation bundled with Perl.
Perl has the basic five arithmetic operators:
These operators work on both integers and floating-point values (and may give you unexpected results if you apply them to strings, as well).
Perl also has a
operator, which computes the remainder of two
17 % 3 is 2, because 2 is left over
when you divide 3 into 17.
Perl also has autoincrement and autodecrement operators:
++ add one -- subtract one
the previous six operators, these change a variable's value.
$x++ adds one to
$x, changing 4 to 5 (or 'a' to 'b').
All scalars, whether numbers or strings, are represented as sequences of individual bits "under the hood." Every once in a while, you need to manipulate those bits, and Perl provides five operators to help:
Two strings may be concatenated—joined together end to end—with the dot operator:
'This is a ' . 'joined string'
This results in the value
A string may be repeated with the
print "Hear ye! " x 3;
This prints out:
Hear ye! Hear ye! Hear ye!
operators are unary operators that test files for certain
characteristics, such as
-e $file, which
true if the file