加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 双正斜杠在这里是什么意思?

发布时间:2020-12-15 21:13:27 所属栏目:大数据 来源:网络整理
导读:我是Perl的新人,在工作中遇到了这段代码,我搜索了一段时间,但没有找到答案.任何人都可以用简单的英文解释其功能吗?谢谢. my $abc = delete $args{ 'abc' } // croak 'some information!'; 解决方法 从此页面: http://perldoc.perl.org/perlop.html#Logical
我是Perl的新人,在工作中遇到了这段代码,我搜索了一段时间,但没有找到答案.任何人都可以用简单的英文解释其功能吗?谢谢.
my $abc = delete $args{ 'abc' } // croak 'some information!';

解决方法

从此页面: http://perldoc.perl.org/perlop.html#Logical-Defined-Or

Although it has no direct equivalent in C,Perl’s // operator is related to its C-style or. In fact,it’s exactly the same as ||,except that it tests the left hand side’s definedness instead of its truth. Thus,EXPR1 // EXPR2 returns the value of EXPR1 if it’s defined,otherwise,the value of EXPR2 is returned. (EXPR1 is evaluated in scalar context,EXPR2 in the context of // itself). Usually,this is the same result as defined(EXPR1) ? EXPR1 : EXPR2 (except that the ternary-operator form can be used as a lvalue,while EXPR1 // EXPR2 cannot). This is very useful for providing default values for variables. If you actually want to test if at least one of $a and $b is defined,use defined($a // $b).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读