加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl比较运算符输出

发布时间:2020-12-16 06:24:34 所属栏目:大数据 来源:网络整理
导读:我不确定比较的输出是什么.例如,考虑一下 $rr = 12;$qq = 21;print $rr; #nothing printedprint $qq; #1 printed $rr是空字符串吗?这种行为是否记录在某处?或者如何确定? 我在Schwartz等人的Learning Perl中寻找答案,但无法立即解决问题. 解决方法 http:/
我不确定比较的输出是什么.例如,考虑一下

$rr = 1>2;
$qq = 2>1;

print $rr; #nothing printed
print $qq; #1 printed

$rr是空字符串吗?这种行为是否记录在某处?或者如何确定?

我在Schwartz等人的Learning Perl中寻找答案,但无法立即解决问题.

解决方法

http://perldoc.perl.org/perlop.html#Relational-Operators:

Perl operators that return true or false generally return values that can be safely used as numbers. For example,the relational operators in this section and the equality operators in the next one return 1 for true and a special version of the defined empty string,“”,which counts as a zero but is exempt from warnings about improper numeric conversions,just as “0 but true” is.

所以返回的是字符串上下文中的空字符串,数字上下文中为0.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读