[ACCEPTED]-What does !! (double exclamation point) mean?-negation
It is just two !
boolean not operators sitting 8 next to each other.
The reason to use this 7 idiom is to make sure that you receive a 6 1
or a 0
. Actually it returns an empty string 5 which numifys to 0. It's usually only used 4 in numeric, or boolean context though.
You 3 will often see this in Code Golf competitions, because 2 it is shorter than using the ternary ? :
operator 1 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
not-not.
It converts the value to a boolean 1 (or as close as Perl gets to such a thing).
Because three other answers claim that the 4 range is "0" or "1", I just thought I'd 3 mention that booleans in Perl (as returned 2 by operators like ==
, not
, and so on) are undef
and 1 1
, not 0
and 1
.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.