Comparing 2 Strings Using >

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akino877
    New Member
    • Nov 2007
    • 37

    Comparing 2 Strings Using >

    Hello,

    I am new to Perl. And I am trying the following code:

    Code:
    if ( "ape" > "aaxxxx" ) {
       print "Greater\n";
    }
    else {
       print "Not greater\n";
    }
    And it printed "Not greater". I wonder if someone could please tell me why?

    Thank you so much for your help - Akino
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    The > operator does a numerical comparison. You need to use one of the string comparison operators such as eq or ne.
    Last edited by RonB; Dec 4 '13, 10:03 PM.

    Comment

    Working...