gpt4 book ai didi

perl - Perl 中是否有内置的 true/false bool 值?

转载 作者:行者123 更新时间:2023-12-04 02:44:15 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:




10年前关闭。




Possible Duplicate:
How do I use boolean variables in Perl?


[root@ ~]$ perl -e 'if(true){print 1}'
1
[root@ ~]$ perl -e 'if(false){print 1}'
1

我都惊呆了 truefalse通过 if ...

最佳答案

如果你严格运行它:

perl -Mstrict -e 'if(true) { print 1 }'

你会得到原因:
Bareword "true" not allowed while "strict subs" in use at -e line 1.

它被解释为字符串 "true""false"这总是正确的。 Perl 中未定义常量,但您可以自己定义:
use constant { true => 1, false => 0 };
if(false) { print 1 }

关于perl - Perl 中是否有内置的 true/false bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6936194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com