Полезная информация

Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 3.4 Array Operators and FunctionsChapter 3
Arrays and List Data
Next: 3.6 <STDIN> as an Array

3.5 Scalar and List Context

As you can see, each operator is designed to operate on some specified combination of scalars or lists, and returns either a scalar or a list. If an operator or function expects an operand to be a scalar, we say that the operand or argument is being evaluated in a scalar context. Similarly, if an operand or argument is expected to be a list value, we say that it is being evaluated in a list context.

Normally, the context is fairly insignificant. But, sometimes you get a completely different operation depending on whether you are within a scalar or a list context. For example, @fred returns the contents of the @fred array in a list context, but the length of the same array in a scalar context. These subtleties are mentioned when each operator and function is described.

A scalar value used within an array context is promoted to a single-element array.

Previous: 3.4 Array Operators and FunctionsLearning Perl on Win32 SystemsNext: 3.6 <STDIN> as an Array
3.4 Array Operators and FunctionsBook Index3.6 <STDIN> as an Array