- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是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-styleor
. 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 ofEXPR1
if it's defined, otherwise, the value ofEXPR2
is returned. (EXPR1
is evaluated in scalar context,EXPR2
in the context of//
itself). Usually, this is the same result asdefined(EXPR1) ? EXPR1 : EXPR2
(except that the ternary-operator form can be used as a lvalue, whileEXPR1 // EXPR2
cannot, and EXPR1 will only be evaluated once). 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, usedefined($a // $b)
.
关于perl - 这里的双斜杠是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23873379/
我是一名优秀的程序员,十分优秀!