"Perl for Perl Newbies" - Part 1ExpressionsOperators and Precedence

3.1. Operators and Precedence

Here are some perl operators of interest.

+ , - , * , /

Respectively adds, subtracts, multiplies and divides two floating point numbers.

a ** b

Raises "a" to the power of "b". Works on floating point numbers too.

a . b

Concatenates two strings. The comma (,) as used by print does not really concatenates two strings, but rather prints them one after the other. (There's a subtle difference in functionality of the print command too, but we won't get into that, now).

print "Hello," . " " . "World!" . "\n" .
    "And this is the second line.\n";

a % b

Returns the modulo (remainder) of "b" from "a". If "a" and "b" are not integers they are rounded to an integral value.

( sub-expr )

Makes sure that sub-expr is evaluated as a separate sub-expression , an operation that could override the default operator precedence.

There are many more, but they will be covered later. For a complete list and more detailed information about the various perl operators consult the "perlop" document on your system.

Written by Shlomi Fish