Perl Operators   «Prev  Next»
Lesson 13Named unary and list operators (functions)
ObjectiveExamine how function calls work as operators.

Named unary and list Operators (Functions)

Syntactically, function calls are actually operators. They evaluate from right to left, and the return value can be a term.
There are basically two classes of function-call operators:
  1. List operators
  2. Named unary operators

List Operators

Functions like print, which take a list as an argument, are list operators.
Because they take lists as arguments, they operate on all list items to the right of the function call unless otherwise restrained. So if a print statement contained a function that operated on a list and no parentheses were applied, the "inner" function would apply itself to every element to its right.
For example, in the MouseOver applet below, move your mouse over print to see what would be printed and over join to see what would be joined.

Perl List Operators
  1. "string ","a:b:c:d:e:f","other things","\n"
  2. "a:b:c:d:e:f"
  3. "string ","a:b:c:d:e:f:other things:\n"
  4. "a:b:c:d:e:f:other things:\n"

named unary List operators

Named unary operators

Functions like uc (uppercase), which expect only one argument, are syntactically named unary operators. That means that they take one argument, and one argument only. So in this example, no parenthesis are necessary:

print "string ", uc "another ",
"string\n";
The only string that will be uppercased is "another " because uc is not a list operator.

Functions that are list operators

It is beyond the scope of this course to describe every one of Perl's built-in functions (there are over 200 of them), but here's a list of all the functions that are list operators.
This should be useful for you to know when you will and will not need to use parenthesis.

Advanced Perl Programming