Operators#

Perl’s operator inventory is large but the structure is regular. Operators group into a handful of families — arithmetic, comparison, logical, bitwise, regex binding, assignment — and a few one-off mechanisms (range, ternary, comma, arrow, subscripts). This reference is split into one page per family.

PetaPerl implements the full Perl 5 operator set with identical semantics: same precedence, same associativity, same context rules. Differences are localised to the PetaPerl-specific notes at the bottom of each page where they apply.

Choose a family#

  • Arithmetic+ - * / % ** and the unary +/-.

  • String. (concatenation), x (repetition).

  • Numeric comparison< <= == >= > != <=>.

  • String comparisonlt le eq ge gt ne cmp (lexicographic).

  • Logical&& || // ! and or not xor and the short-circuit / operand-return rule.

  • Bitwise& | ^ ~ << >>.

  • Range.. and ..., with their list/scalar dual semantics.

  • Binding=~ and !~ connect strings with regex.

  • Assignment= and the compound forms (+= .= ||= //= etc.).

  • Ternary?:.

  • Subscript[], {}, slices, deref braces.

  • Arrow-> (deref, method call).

  • Comma, and the fat comma =>.

  • Precedence — the full precedence table and the named-unary parse rule that confuses everyone the first time.

Cross-cutting concepts#

A few ideas appear in every chapter. Read these once and you will recognise them throughout the rest:

  • Context. Operators evaluate their operands in a specific context (numeric, string, list, scalar, boolean). Many of the surprises in Perl arithmetic and comparison come from context coercion at the operand boundary, not from the operator itself.

  • Short-circuit. &&, ||, //, and, or evaluate left-to-right and stop as soon as the result is determined. The whole expression’s value is the last thing actually evaluated — which is one of its operands, not a normalised true/false. See logical and the boolean-logic tutorial.

  • Precedence. Tells you how operators bind when parentheses do not. The full table is in precedence and every page links the rows it cares about.

  • Lvalue. Most operators produce rvalues (values you can read). A few — assignment, deref, ternary in some shapes — produce lvalues (locations you can write to).

See also#