Why don't lt and gt in Perl work for comparing real numbers?

Let's look at the following perl code

if ($a lt 0.00 or $a gt 100.000)
{
    print "a must be between 0 and 100 \n";
    exit 1
}
exit 0

Assume that a is 5. The above code will exit the failure state, since a is not between 0 and 100.

Simply replacing ltand gton the actual statements that they represent, <and >respectively, give the expected results. Replacing 100 with a number starting with 9 will also give the expected result.

Why do Perl comparison operators tell me that 5 is not between 0 and 100?

+4
source share
2 answers

lt gt - , , < >. Perl , ( , , python, ).

+11

perl lt gt < >. perl perlop , :

Binary "<" returns true if the left argument is numerically less than the right argument.
Binary ">" returns true if the left argument is numerically greater than the right argument.
Binary "<=" returns true if the left argument is numerically less than or equal to the right argument.
Binary ">=" returns true if the left argument is numerically greater than or equal to the right argument.
Binary "lt" returns true if the left argument is stringwise less than the right argument.
Binary "gt" returns true if the left argument is stringwise greater than the right argument.
Binary "le" returns true if the left argument is stringwise less than or equal to the right argument.
Binary "ge" returns true if the left argument is stringwise greater than or equal to the right argument.

perl , perl . , perl , , - , lt gt < >

+6

Source: https://habr.com/ru/post/1615313/


All Articles