Quoted from perldoc:
Binary "==" returns true if the left argument is numerically equal to the right argument.
Binary "eq" returns true if the left argument is stringwise equal to the right argument.
实际上也就是说==返回是是否数值相等,而eq返回的是字符相等。
结果只有numerically equal。
PS:perl会自动转换字符串。$str1 == $str2中的值都是1
Binary "==" returns true if the left argument is numerically equal to the right argument.
Binary "eq" returns true if the left argument is stringwise equal to the right argument.
实际上也就是说==返回是是否数值相等,而eq返回的是字符相等。
- Perl code
- $str1 = "1 -the first str"; $str2 = "1 -the second str"; print "numerically equal\n" if($str1 == $str2); print "stringwise equal\n" if($str1 eq $str2);
结果只有numerically equal。
PS:perl会自动转换字符串。$str1 == $str2中的值都是1
实际上也就是说==返回是是否数值相等,而eq返回的是字符相等
本文介绍了Perl语言中用于比较的两个操作符:== 和 eq 的区别。== 用于数值比较,而 eq 则用于字符串的逐字符比较。通过一个示例展示了两者在实际使用中的不同结果。
755

被折叠的 条评论
为什么被折叠?



