Construct Meaning
========= ==========================================
\n Newline
\r Return
\t Tab
\f Formfeed
\b Backspace
\v Vertical tab
\a Bell
\e Escape
07 Any octal ASCII value (here, 007 = bell)
\x7f Any hex ASCII value (here, 7f = delete)
\cC Any control character (here, control C)
\\ Backslash
\” Double quote
\l Lowercase next character
\L Lowercase all following letters until \E
\u Uppercase next letter
\U Uppercase all following letters until \E
\E Terminate \L or \U
Double-quoted strings are variable interpolated which means that some variable names within the strings will be replaced with their current values when the string is used in a program.
Operators
An operator produces a new value (or result) from one or more operands (values). An example of an operator is the ‘+’ sign which represents the plus operator because it takes two values (numbers) and sums them together producing a new value or result.
Perl’s operators and expressions are a superset of those provided in other ALGOL/Pascal type programming languages of which C and C++ are examples. An operator expects either numeric or string operators to operate on (you can use a combination as well). Perl performs a conversion of the operand using internal rules which are described later on.
Operators for Numbers
As would be expected Perl provides the typical operators for arithmetic – addition, subtraction, multiplication and division. In keeping with the earlier Fortran analogy Perl provides a FORTRAN-like exponentiation operator which previously wasn’t available in C (it may be now but i have looked at the C or C++ standard in several years so I don’t know if it is or isn’t at this time), this operator uses the double asterisk operator **, for example, 3**3 equates to 3 to the third power or 3*3*3 which equals 27 I believe. If the result or value of the operation can not fit into a double-precision floating-point number (remember our earlier note that Perl treats all numbers as double-precision floating point numbers) such as a negative number to a non-integer exponent or a large enough number to an exponent whose result exceeds the boundaries of double-precision floating-point then Perl will issue a fatal error.
In addition to the exponential operator, Perl also provides the modulus operator as does C. An example of an operation using a modulus operator is: 20 % 3 which translates to english as the remainder of dividing 20 by 3 and on a further note if you use real numbers such as 20.5, 4.5, etc. the operands are converted to their integer values as the first step in the modulus operation which would translate to 20.5 / 4.5 -> 20 / 4 and in this case the result of the modulus operation would be 0 because there is no remainder when 20 is divided by 4. In the previous example 20 % 3 the remainder would be 3.
The logical comparison operators are the same as those found in the C programing language which are ( < <= == > != <=), and the comparison of two values numerically, returning a true of false value (result). To illustrate one of the operators we’ll use the greater than operator, for 10 > 12 Perl will return false because 10 is not greater than 12, while 10 != 10 will return false because 10 IS equal to 10. The representation of the return results (values) are in the same format as C uses, meaning Perl returns the value of zero equals False, one equals or equates to True.
String Operators
Perl offers the period “.” as the operator to concatenate string values making concatenation very easy and intuitive. An example would be: “hello world” . “world” which equates to “hello worldhello world” and another example would be: “hello world”.” “.”hello world”.”\n” translates to “hello world hello world\n”.
Whereas, other languages and unix shells offer variations on the concatenation theme in Perl you have to explicitly instruct Perl to perform the concatenation operation by specifying the concatenation character “.”.
The set of comparison operators for strings are Fortran-like too, as in lt for less-than, gt for greater-than, etc. The operators compare the ASCII values of the characters the string is comprised of.