&是什么QUOT; 0,但真正的"在Perl意味着什么呢? [英] What does "0 but true" mean in Perl?

查看:198
本文介绍了&是什么QUOT; 0,但真正的"在Perl意味着什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释究竟是什么字符串0,但真正的是指在Perl?据我了解,它的整数比较等于零,但作为一个布尔值使用时,计算结果为真。它是否正确?这是语言的正常行为或者这是作为跨preTER一个特例?

Can someone explain what exactly the string "0 but true" means in Perl? As far as I understand, it equals zero in an integer comparison, but evaluates to true when used as a boolean. Is this correct? Is this a normal behavior of the language or is this a special string treated as a special case in the interpreter?

推荐答案

这是语言的正常行为。引述 perlsyn 手册页:

It's normal behaviour of the language. Quoting the perlsyn manpage:

数字0,字符串'0'和'',空列表()和民主基金
  在布尔上下文全是假的。所有其他值都是如此。否定
  一个真正的价值!或者不是返回一个特殊的假值。
  时,因为它被视为''的字符串进行评价,但是作为一个数字,它是
  视为0。

The number 0, the strings ’0’ and ’’, the empty list "()", and "undef" are all false in a boolean context. All other values are true. Negation of a true value by "!" or "not" returns a special false value. When evaluated as a string it is treated as ’’, but as a number, it is treated as 0.

由于这一点,需要有从系统调用需要返回0作为一个(成功)的返回值返回0,并留下了一种信号通过实际返回一个假值故障状态下的一种方式。 0,但真正的供应这一目的。

Because of this, there needs to be a way to return 0 from a system call that expects to return 0 as a (successful) return value, and leave a way to signal a failure case by actually returning a false value. "0 but true" serves that purpose.

这篇关于&是什么QUOT; 0,但真正的"在Perl意味着什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆