Jan 16, 2003, 1:09 AM
Post #12 of 13
Re: [skirrow] Length checks not working correctly
[In reply to]
My apologies, I should proof read!!
Let me try and explain again. I want all inputs that are greater than 7 characters in length to be excepted. However, when I use the following code:
$password = $input_password if (length($input_password) gt "7");
Only inputs of 8 and 9 characters in length are accepted. Not 10 characters and above. This is my problem. Is this a bug with Perl or what as surely it should only reject inputs less than 8 characters in length.
Not a bug with Perl, but a bug with your understanding of Perl.
The comparison operators that look like words ('eq', 'ne', 'gt', 'cmp', etc) do a comparison based on the ASCII value of their operands. Under this system the string "10" sorts before the string "2" because "1" has a lower ASCII value than "2". This is identical to the processing that makes "an" sort before "I".
If you want to compare the values as numbers, then you'll need to use the numerical comparison operators. They're the ones that look like mathematical symbols - '=='. '<>', '>', '<=>, etc.
Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks