perl中==操作和eq操作区别

来源:互联网 发布:ios计算网络图片大小 编辑:程序博客网 时间:2024/05/21 00:56

$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,少用==

0 0