Sep 5, 2012 #1 S Sumitha Sudhakaran Junior Member level 2 Joined Aug 7, 2012 Messages 24 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Location Bangalore Activity points 1,440 I want to compare 2 multi digit numbers, say $x = 99 and $y = 158.. the operation: if ($x gt $y) {print $x;} the result gives 99 as the answer.. Probably because 9 is greater than 1.. Wats the command to get the correct answer in PERL???
I want to compare 2 multi digit numbers, say $x = 99 and $y = 158.. the operation: if ($x gt $y) {print $x;} the result gives 99 as the answer.. Probably because 9 is greater than 1.. Wats the command to get the correct answer in PERL???
Sep 7, 2012 #2 E enob Newbie level 5 Joined May 31, 2012 Messages 9 Helped 1 Reputation 2 Reaction score 1 Trophy points 1,283 Activity points 1,317 The problem is you are using the wrong relational operator. "gt" is for comparing two strings. For example, Code: $string1 = 'cat'; $string2 = 'dog'; if ($string1 ne $string2) { print "Not equal\n"; } else { print "Equal\n"; } You need to use < or > for integers. Code: $x = 99; $y = 158; if ($x > $y){ print $x; } else { print "Not greater than"; } Hope this helps
The problem is you are using the wrong relational operator. "gt" is for comparing two strings. For example, Code: $string1 = 'cat'; $string2 = 'dog'; if ($string1 ne $string2) { print "Not equal\n"; } else { print "Equal\n"; } You need to use < or > for integers. Code: $x = 99; $y = 158; if ($x > $y){ print $x; } else { print "Not greater than"; } Hope this helps