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

Learning Perl

Learning PerlSearch 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 and function 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, this is fairly insignificant. But sometimes you get completely different behavior 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 a list context is promoted to a single-element array.


Previous: 3.4 Array Operators and FunctionsLearning PerlNext: 3.6 <STDIN> as an Array
3.4 Array Operators and FunctionsBook Index3.6 <STDIN> as an Array