问题描述
我找到了我需要的一些Perl代码的示例,但是其中有一些我不认识的东西.
I found an example of some Perl code I needed, but it had something in it that I didn't recognise.
my $i //= '08';
我在任何地方都找不到对此的参考!它似乎与以下内容相同:
I can't find any reference to this anywhere! It appears to be the same as:
my $i = '08';
我想念什么吗?
推荐答案
The //=
operator is the assignment operator version of the //
or 'logical defined-or' operator.
在my
变量声明的上下文中,该变量最初是未定义的,因此它 等效于赋值(最好将其写为my $i = '08';
).总体而言,
In the context of a my
variable declaration, the variable is initially undefined so it is equivalent to assignment (and would be better written as my $i = '08';
). In general, though,
$i //= '08';
是以下内容的简写:
$i = (defined $i) ? $i : '08';
在Perl运算符(perldoc perlop
)中的两个位置(分别在赋值运算符"部分下,并在逻辑定义或"部分中完整记录了该文档).它是在Perl 5.10.0中添加的.
It is documented in the Perl operators (perldoc perlop
) in two places (tersely under the assignment operators section, and in full in the section on 'logical defined-or'). It was added in Perl 5.10.0.
这篇关于在Perl中什么是//=?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!