开发者

Java's compareTo() function equivalent in Perl?

开发者 https://www.devze.com 2023-01-12 14:46 出处:网络
Wh开发者_如何转开发at\'s the Perl function that achieves the same thing as compareTo() in Java? I know about eq and ne but I want to compare to see if one string is greater than another.You actually h

Wh开发者_如何转开发at's the Perl function that achieves the same thing as compareTo() in Java? I know about eq and ne but I want to compare to see if one string is greater than another.


You actually have cmp (for strings) and <=> (for numbers) operators. See the Equality Operators section in perlop.

Example:

print "foo" cmp "bar"; # prints 1


gt should do the trick

Edit: actually, cmp would be more similar to compareTo(), gt would just tell you if the string is greater than then the other.

0

精彩评论

暂无评论...
验证码 换一张
取 消