Perl比较运算符输出

前端之家收集整理的这篇文章主要介绍了Perl比较运算符输出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不确定比较的输出是什么.例如,考虑一下

$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.

猜你在找的Perl相关文章