The symbol =
is compiled into one of two assignment operators:
- A list assignment operator (
aassign
) is used if the left-hand side (LHS) of a =
is some kind of aggregate.
- A scalar assignment operator (
sassign
) is used otherwise.
The following are considered to be aggregates:
- Any expression in parentheses (e.g.
(...)
)
- An array (e.g.
@array
)
- An array slice (e.g.
@array[...]
)
- A hash (e.g.
%hash
)
- A hash slice (e.g.
@hash{...}
)
- Any of the above preceded by
my
, our
or local
There are two differences between the operators.
Context of Operands
The two operators differ in the context in which their operands are evaluated.
The scalar assignment evaluates both of its operands in scalar context.
# @array evaluated in scalar context.
my $count = @array;
The list assignment evaluates both of its operands in list context.
# @array evaluated in list context.
my @copy = @array;
# @array evaluated in list context.
my ($first) = @array;
Value(s) Returned
The two operators differ in what they return.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…