至于最后一个qw// qw/$a/就是'$a', 而另一个是'$b',都转成数字是0,所以相等
2011/1/21 Jeova Sanctus Unus <[email protected]>: > 找到了 > perlop > Equality Operators > Binary "<=>" returns -1, 0, or 1 depending on whether the left > argument is numerically less than, equal to, or greater than the right > argument. If your platform supports NaNs (not-a-numbers) as numeric > values, using them with "<=>" returns undef. NaN is not "<", "==", > ">", "<=" or ">=" anything (even NaN), so those 5 return false. NaN != > NaN returns true, as does NaN != anything else. If your platform > doesn't support NaNs then NaN is just a string with numeric value 0. > perl -le '$a = "NaN"; print "No NaN support here" if $a == $a' > perl -le '$a = "NaN"; print "NaN support here" if $a != $a' > > 在 2011年1月21日 上午8:42,Jeova Sanctus Unus <[email protected]> 写道: >> 等下..... >> 你这个怎么找到的? >> 我刚才试了下.... >> 发现你的字符串是"nAn"开头,于是就被转换成了nan.... >> 对于nan是否相等我也有疑问,有人能说说么? >> 我翻翻资料 >> >> 在 2011年1月21日 上午7:33,Jeova Sanctus Unus <[email protected]> 写道: >>> 你用错了操作符 >>> 应该用eq,ne >>> 转成数字后是nan,然后nan和nan比较都是不等的.所以.... >>> >>> 在 2011年1月21日 上午12:08,Andy Chen <[email protected]> 写道: >>>> Run following code, tell me your result. >>>> >>>> #!/usr/bin/perl >>>> >>>> my $a= "nAnQpW9mVV0TWLgbLgriCu6Tp2f2ymI7HUZfJS"; >>>> my $b= "nAnQpW9mVV0TWLgbLgriCu6Tp2f2ymI7HUZfJS"; >>>> >>>> if($a != $b) >>>> { >>>> print("not equal!\n"); >>>> } >>>> else >>>> { >>>> print("equal!\n"); >>>> } >>>> >>>> if("$a" != "$b") >>>> { >>>> print("not equal!\n"); >>>> } >>>> else >>>> { >>>> print("equal!\n"); >>>> } >>>> >>>> if(qw/$a/ != qw/$b/) >>>> { >>>> print("not equal!\n"); >>>> } >>>> else >>>> { >>>> print("equal!\n"); >>>> } >>>> >>>> -- >>>> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 >>>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >>>> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 >>>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 >>>> >>> >> > -- 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
