- 论坛徽章:
- 0
|
- #! perl -w
- $line = <STDIN>;
- if ($line == "good"){
- print "that's good";
- }else{
- print "you are wrong!\n"
- }
复制代码
这样可以得到正确的结果,比如输入good,输出
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,即
- #! perl -w
- $line = <STDIN>;
- if ($line eq "good"){
- print "that's good";
- }else{
- print "you are wrong!\n"
- }
复制代码
D:\>perl test.pl
good
you are wrong!
请问这是为什么?如果字符串比较应该怎么写..谢谢了 |
|