In Perl, all functions and operators are aware of their context, and can behave differently in different contexts. The two major contexts are scalar and list. Context can be forced by assigning to a scalar variable or a list variable respectively.

Example: the function localtime returns either a list of nine elements (in list context) or the current time in seconds since January 1, 1970 (in scalar context).

($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = localtime(); # list context
$now = localtime(); # scalar context

An interesting feature is applying scalar context to an array or list. That returns the array's length (number of elements) or the list's last element.


ariels says: You can (also) force scalar context by saying scalar, or list context by evaluating in the (trivial) list context (...).