喜旎果 发表于 2015-12-28 12:45:06

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

  $str1 = "1 -the first str";
  $str2 = "1 -the second str";
  print "numericallyequal\n" if($str1 == $str2);
  print "stringwise equal\n" if($str1 eq $str2);
  
  结果只有numerically equal。 PS:perl会自动转换字符串。$str1 == $str2中的值都是1


实际上也就是说==返回是是否数值相等,而eq返回的是字符相等  
  
  Perl字符串比较,不要用==,要用eq
页: [1]
查看完整版本: perl中==操作和eq操作区别