Why does !1 give me nothing in Perl?

前端 未结 5 1645
青春惊慌失措
青春惊慌失措 2020-12-03 14:29

This is strange. The following:

$sum = !0;
print $sum;

prints out 1 as you would expect. But this

$sum = !1;
print $sum;
         


        
5条回答
  •  被撕碎了的回忆
    2020-12-03 14:33

    The operators that only return a boolean result will always return 1 for true and a special false value that's "" in string contexts but 0 in numeric contexts.

提交回复
热议问题