"Perl Programmers Reference Guide (англ.) (программ.) /19.12.1998/ " - читать интересную книгу автора

other words, Perl overloads certain operations based on
whether the expected return value is singular or plural.
(Some words in English work this way, like "fish" and
"sheep".)

In a reciprocal fashion, an operation provides either a
scalar or a list context to each of its arguments. For
example, if you say

int( )

the integer operation provides a scalar context for the
operator, which responds by reading one line from
STDIN and passing it back to the integer operation, which
will then find the integer value of that line and return
that. If, on the other hand, you say

sort( )

then the sort operation provides a list context for
, which will proceed to read every line available
up to the end of file, and pass that list of lines back to
the sort routine, which will then sort those lines and
return them as a list to whatever the context of the sort
was.

Assignment is a little bit special in that it uses its
left argument to determine the context for the right
argument. Assignment to a scalar evaluates the righthand
side in a scalar context, while assignment to an array or
array slice evaluates the righthand side in a list
context. Assignment to a list also evaluates the
righthand side in a list context.

User defined subroutines may choose to care whether they
are being called in a scalar or list context, but most
subroutines do not need to care, because scalars are
automatically interpolated into lists. See the wantarray
entry in the _p_e_r_l_f_u_n_c manpage.

SSSSccccaaaallllaaaarrrr vvvvaaaalllluuuueeeessss

All data in Perl is a scalar or an array of scalars or a
hash of scalars. Scalar variables may contain various
kinds of singular data, such as numbers, strings, and
references. In general, conversion from one form to
another is transparent. (A scalar may not contain
multiple values, but may contain a reference to an array
or hash containing multiple values.) Because of the
automatic conversion of scalars, operations, and functions