在Perl中什么是//=? [英] What is //= in Perl?

查看:106
本文介绍了在Perl中什么是//=?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了我需要的一些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中什么是//=?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆