将 Perl 中的 String 与"eq"与"[ duplicate ]进行比较

This question already has an answer here:

I am (a complete Perl newbie) doing string compare in an if statement:

If I do following:

if ($str1 == "taste" && $str2 == "waste") { }

I see the correct result (i.e. if the condition matches, it evaluates the "then" block). But I see these warnings:

Argument "taste" isn't numeric in numeric eq (==) at line number x.
Argument "waste" isn't numeric in numeric eq (==) at line number x.

But if I do:

if ($str1 eq "taste" && $str2 eq "waste") { }

Even if the if condition is satisfied, it doesn't evaluate the "then" block.

Here, $str1 is taste and $str2 is waste.

How should I fix this?

</div>

转载于:https://stackoverflow.com/questions/14046669/string-compare-in-perl-with-eq-vs

查看全部
csdnceshi78
程序go
2012/12/26 21:48
  • string
  • perl
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复