


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 means that they both are evaluated as empty strings, or zero, so they are equal. So you have two strings, each of which has no numbers in it at all. If you see more "can't belong to this number" characters before you reach the end of the string (notice that this is contextual e.g., if we'd gotten "0b", anything other any "1" or "0" can't belong), stop, evaluate whatever you have using these rules, and return that.If you hit the end of the string, evaluate the number you have so far using these rules, and return that. When you find the first digit, collect characters as long as they still look like they belong to a number (Note that "0x" is a set of characters that could belong to a number).If you see stuff that isn't numeric or whitespace, stop and return 0. Perl attempts to convert strings to numbers via a very specific procedure: Re: Definition of numerically equal and rationale for 'you' = 'me' Some notes below your chosen depth have not been shown hereīy chromatic (Archbishop) on at 01:29 UTC Re^5: Definition of numerically equal and rationale for 'you' = 'me' Re^4: Definition of numerically equal and rationale for 'you' = 'me' Proper operator for the type of context you want. Perl will do its best to coerce values to the proper typeĭepending on the operators you use. The eq operator treats its operands as strings by
#NUMERICALLY EQUAL DEFINITION HOW TO#
That tell the compiler how to treat a given value during In exchange for not having to declare (or at least track)Įxplicitly what type of data a variable contains orĪ function produces, Perl offers specific type contexts Operator ambiguity is clearly and tastefully described in Modern Perl in the "Numeric, String, and Boolean Context" section on page eight: The elegant dividend that Perl derives from its lack of It explains why, for instance, you so often need uglyĮxplicit coercion via the int function in I'm often saddened by how many language designers were seduced by this unfortunate misfeature. Yes, overloading + to mean either string concatenation or numeric addition is a language design blunder IMHO. Re^3: Definition of numerically equal and rationale for 'you' = 'me'īy eyepopslikeamosquito (Bishop) on at 11:01 UTC
