请帮助我理解以下片段:
my $count = @array;
my @copy = @array;
my ($first) = @array;
(my $copy = $str) =~ s/\\/\\\\/g;
my ($x) = f() or die;
my $count = () = f();
print($x = $y);
print(@x = @y);
u3r8eeie1#
[* 此答案也可在表格格式here中找到。*]符号=被编译成两个赋值运算符之一:
=
aassign
sassign
以下被视为聚合物:
(...)
@array
@array[...]
%hash
@hash{...}
my
our
local
运算符之间有两个区别。
这两个运算符在计算其操作数的上下文中不同。
# @array evaluated in scalar context. my $count = @array;
# @array evaluated in scalar context.
# @array evaluated in list context. my @copy = @array;
# @array evaluated in list context.
# @array evaluated in list context. my ($first) = @array;
这两个运算符的返回内容不同。
# The s/// operates on $copy. (my $copy = $str) =~ s/\\/\\\\/g;
# The s/// operates on $copy.
# Prints $x. print($x = $y);
# Prints $x.
# Only dies if f() returns an empty list. # This does not die if f() returns a # false scalar like zero or undef. my ($x) = f() or die;
# Only dies if f() returns an empty list.
# This does not die if f() returns a
# false scalar like zero or undef.
# $counts gets the number of scalars returns by f(). my $count = () = f();
# $counts gets the number of scalars returns by f().
# Prints @x. print(@x = @y);
# Prints @x.
1条答案
按热度按时间u3r8eeie1#
[* 此答案也可在表格格式here中找到。*]
符号
=
被编译成两个赋值运算符之一:=
的左侧(LHS)是某种聚合,则使用 * 列表赋值运算符 *(aassign
)。sassign
)。以下被视为聚合物:
(...)
)@array
)@array[...]
)%hash
)@hash{...}
)my
、our
或local
的上述任何一项运算符之间有两个区别。
操作数上下文
这两个运算符在计算其操作数的上下文中不同。
返回的值
这两个运算符的返回内容不同。