I hit some strange behavior when doing simple comparisons of numbers with leading zeros.
I found that if I don't quote a number I am using for comparison, I sometimes get incorrect result.
Here is my code that demonstrates the issue:
#!/usr/bin/perl -w use strict; my @numbers = qw(022000 022300 022400 022800 023600 024700 024500 0249 +00); foreach my $number(@numbers) { my $compRes1 = $number < 060000; my $compRes2 = $number < '060000'; print "For $number, result1 is $compRes1, result2 is $compRes2\n"; }
Here is the output that I get:
For 022000, result1 is 1, result2 is 1
For 022300, result1 is 1, result2 is 1
For 022400, result1 is 1, result2 is 1
For 022800, result1 is 1, result2 is 1
For 023600, result1 is 1, result2 is 1
For 024700, result1 is , result2 is 1
For 024500, result1 is 1, result2 is 1
For 024900, result1 is , result2 is 1
As can be seen, for '024700' and '024900', result1 is empty while result2 is correct.
I tried this both on 32 and 64 bit Perl, older and newer versions.
I am not sure if this is a problem, just very strange.
Any ideas as to how this can happen are greatly appreciated.
In reply to strange comparison results by sduser81
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |