初学perl,问个小问题

初学perl,问个小问题



[Copy to clipboard] [ - ]
CODE:
#! perl -w
  $line = <STDIN>;
  if ($line == "good"){
  print "that's good";
  }else{
          print "you are wrong!\n"
  }

这样可以得到正确的结果,比如输入good,输出

QUOTE:
D:\>perl test.pl
good
Argument "good" isn't numeric in numeric eq (==) at test.pl line 3, <STDIN> line
1.
Argument "good\n" isn't numeric in numeric eq (==) at test.pl line 3, <STDIN> li
ne 1.
that's good

而把==换成eq,即

[Copy to clipboard] [ - ]
CODE:
#! perl -w
  $line = <STDIN>;
  if ($line eq "good"){
  print "that's good";
  }else{
          print "you are wrong!\n"
  }



QUOTE:
D:\>perl test.pl
good
you are wrong!

请问这是为什么?如果字符串比较应该怎么写..谢谢了
$line = <STDIN>;
chomp($line);
谢谢你..还是不太明白..我是想比较2个字符串..eq应该是可以的吧..为什么我写出的代码跑出来不是这个结果呢
因为从 STDIN 读进来的字串结尾有 换行符。
谢谢..明白了..