这是什么! (双感叹号)是什么意思? [英] What does !! (double exclamation point) mean?
问题描述
在下面的code,从博客文章通过别名的,我注意到了使用双感叹号 !!
的。我想知道这是什么意思,并在那里我可以进去以后找到像这样的Perl的语法解释。 (是的,我已经搜索 !!
位于 perlsyn )。
In the code below, from a blog post by Alias, I noticed the use of the double exclamation point !!
. I was wondering what it meant and where I could go in the future to find explanations for Perl syntax like this. (Yes, I already searched for !!
at perlsyn).
package Foo;
use vars qw{$DEBUG};
BEGIN {
$DEBUG = 0 unless defined $DEBUG;
}
use constant DEBUG => !! $DEBUG;
sub foo {
debug('In sub foo') if DEBUG;
...
}
更新
感谢您的答案。
UPDATE
Thanks for all of your answers.
下面是别的东西,我只是发现有关列表壁球操作 X !!
Here is something else I just found that is related The List Squash Operator x!!
推荐答案
它只是两个!
布尔运算符不坐在旁边给对方。
It is just two !
boolean not operators sitting next to each other.
使用这个成语的原因是为了确保您收到 1
或 0
。实际上,它返回一个numifys 0它通常只在数字使用,或一个空字符串布尔上下文虽然。
The reason to use this idiom is to make sure that you receive a 1
or a 0
. Actually it returns an empty string which numifys to 0. It's usually only used in numeric, or boolean context though.
您经常会看到这样的<一个href=\"http://www.google.com/search?hl=en&q=site%3astackoverflow.com/questions+$c$c-golf+perl\">$c$c高尔夫比赛,因为它比使用三元短?
运营商 1
和 0
<子>( $ ?测试1:0
)
You will often see this in Code Golf competitions, because it is shorter than using the ternary ? :
operator with 1
and 0
($test ? 1 : 0
).
!! undef == 0
!! 0 == 0
!! 1 == 1
!! $obj == 1
!! 100 == 1
undef ? 1 : 0 == 0
0 ? 1 : 0 == 0
1 ? 1 : 0 == 1
$obj ? 1 : 0 == 1
100 ? 1 : 0 == 1
这篇关于这是什么! (双感叹号)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!