The functions in this section can serve as terms in an expression. They
fall into two major categories: list operators and named unary operators.
These differ in their precedence relationship with a following comma. (See
the precedence table in the perlop manpage.) List operators take more than one argument, while unary operators can never take more than one argument. Thus, a comma terminates the argument of a unary operator, but merely separates the arguments of a list operator.
A unary operator generally provides a scalar context to its argument, while a list operator may provide either scalar and list contexts for its arguments. If it does both, the scalar arguments will be first, and the list argument will follow. (Note that there can ever be only one list argument.) For instance, splice() has three scalar arguments followed by a list.
In the syntax descriptions that follow, list operators that expect a list (and provide list context for the elements of the list) are shown with
LIST as an argument. Such a list may consist of any combination of scalar arguments or list values; the list values will be included in the list as if each individual element were interpolated at that point in the list, forming a longer single-dimensional list value. Elements of the
LIST should be separated by commas.
Any function in the list below may be used either with or without
parentheses around its arguments. (The syntax descriptions omit the
parentheses.) If you use the parentheses, the simple (but occasionally
surprising) rule is this: It LOOKS like a function, therefore it IS a function, and precedence doesn't matter. Otherwise it's a list operator
or unary operator, and precedence does matter. And whitespace between the
function and left parenthesis doesn't count--so you need to be careful
print 1+2+4; # Prints 7.
print(1+2) + 4; # Prints 3.
print (1+2)+4; # Also prints 3!
print +(1+2)+4; # Prints 7.
print ((1+2)+4); # Prints 7.
If you run Perl with the -w switch it can warn you about this. For example, the third line above
print (...) interpreted as function at - line 1.
Useless use of integer addition in void context at - line 1.
For functions that can be used in either a scalar or list context,
nonabortive failure is generally indicated in a scalar context by returning
the undefined value, and in a list context by returning the null list.
Remember the following important rule: There is no rule that relates the behavior of an expression in list context to its behavior
in scalar context, or vice versa. It might do two totally different things.
Each operator and function decides which sort of value it would be most
appropriate to return in a scalar context. Some operators return the length
of the list that would have been returned in list context. Some operators
return the first value in the list. Some operators return the last value in
the list. Some operators return a count of successful operations. In
general, they do what you want, unless you want consistency.
An named array in scalar context is quite different from what would at
first glance appear to be a list in scalar context. You can't get a list
like (1,2,3) into being in scalar context, because the compiler knows the context at
compile time. It would generate the scalar comma operator there, not the
list construction version of the comma. That means it was never a list to
In general, functions in Perl that serve as wrappers for system calls of
the same name (like chown(2),fork(2),closedir(2), etc.) all return true when they succeed and undef otherwise, as is usually mentioned in the descriptions below. This is different from the
C interfaces, which return
-1 on failure. Exceptions to this rule are wait(),
waitpid(), and syscall(). System calls also set the special $!
variable on failure. Other functions do not, except accidentally.
We are painfully aware that these documents may contain incorrect links and
misformatted HTML. Such bugs lie in the automatic translation process
that automatically created the hundreds and hundreds of separate documents that you find here. Please do
not report link or formatting bugs, because we cannot fix
per-document problems. The only bug reports that will help us are those
that supply working patches to the installhtml or pod2html
programs, or to the Pod::HTML module itself, for which I and the entire
Perl community will shower you with thanks and praises.
If rather than formatting bugs, you encounter substantive content errors in these documents, such as mistakes in
the explanations or code, please use the perlbug utility included
with the Perl distribution.
--Tom Christiansen, Perl Documentation Compiler and Editor