What'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.
Asked
Active
Viewed 321 times
2

HoldOffHunger
- 18,769
- 10
- 104
- 133

vette982
- 4,782
- 8
- 34
- 41
-
4You'll get better answers to questions like this if you explain exactly what `compareTo` does in Java. Not all Perl programmers know Java. – cjm Aug 23 '10 at 21:01
2 Answers
17
You actually have cmp
(for strings) and <=>
(for numbers) operators.
See the Equality Operators section in perlop.
Example:
print "foo" cmp "bar"; # prints 1
5
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.

cam
- 14,192
- 1
- 44
- 29