Perl Operators   «Prev  Next»
Lesson 2 Terms, operators, and expressions
ObjectiveFamiliarize yourself with how term, operator, and expression are used in Perl.

Terms, Operators, and Expressions in Perl

Expressions and statements are often the same thing in Perl. Strictly speaking, an expression is anything that has a result, even if that result is the undef value. In other words, just about everything in Perl is an expression.
The undef value is a special value in Perl which represents an variable which is in a uninitialized or undefined state. There is also a corresponding function, undef, that can be used to undefine a variable which already has a value. An operator is a symbol (or a keyword) that operates on various terms to return a result. The term(s) of the operator are the various expressions on either or both sides of the operator that provide the values on which the operator operates.

Expression consisting of 1) term and 2) operator
Expression consisting of 1) term and 2) operator

Some operators work with terms on both sides; others work on terms on just one side of the operator. Those that work on just one side are called unary operators. In fact, there is even one operator which works on three terms, which is called a ternary operator.
Often, however, you will have expressions with more than one operator. In those cases your result may well depend on which operator evaluates first! In the next lesson you will learn about the relative precedence of Perl operators.