Do you know where your variables are? | |
PerlMonks |
Re: Definition of numerically equal and rationale for 'you' == 'me'by pemungkah (Priest) |
on Mar 01, 2012 at 22:53 UTC ( [id://957346]=note: print w/replies, xml ) | Need Help?? |
Numerically is the key word here. Perl attempts to convert strings to numbers via a very specific procedure:
If you had use warnings on, it would have told you that you were comparing two strings and that you would probably not get the intended results. This is one of those cases where "what you meant" and "what you said" do not match, and the warning would have let you know that. As a note, this is why "0 but true" - the "true zero" - is indeed that: a value equal numerically to zero, but when evaluated as part of a logical expression is true. It's zero by the number-collecting logic (start with "0", next character is " ", so end of number, value 0) and not a null string, undef, zero, or quoted zero by the test-for-false logic. Edit: corrected number-detection logic: non-whitespace leading characters cause an immediate drop out with a zero value; whitespace doesn't count until you hit the number; any character that "can't belong" causes evaluation to stop. Added "0 but true" why-does-that-work explanation.
In Section
Seekers of Perl Wisdom
|
|