twelve = "12" and then changed it to array.length == twelve it does the
same thing.
You're still compating array.length to "12", but Array#length returns
an integer, not a string. "12" is a string. array.length will return
12 and as Daniel said 12 == "12" is false. Whether you assign "12" to
a variable first or not.
That a typical PHP behaviour, because PHP casts Strings to Ints before comparing. This can be confusing. (Although they sell it as "good usability") Ruby does not know implicit casts and thus 11 != "11". Ruby is not as lax as PHP when it comes to types.
(Fun fact. Did you know that 11 == "11abcde"? Ask PHP. Second FF: Did you know that a variable containing 0 or "0" is empty()?)
Regards,
Florian Gilcher
···
On Jun 30, 2008, at 10:27 AM, Sebastian Hungerecker wrote:
Tj Superfly wrote:
twelve = "12" and then changed it to array.length == twelve it does the
same thing.
You're still compating array.length to "12", but Array#length returns
an integer, not a string. "12" is a string. array.length will return
12 and as Daniel said 12 == "12" is false. Whether you assign "12" to
a variable first or not.
HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826
That a typical PHP behaviour, because PHP casts Strings to Ints before
comparing.
Similar thing with Perl. Perl scalars can be numbers or strings,
depending on the context. Sometimes you have to force them to be one or
the other; e.g. adding 0 to a scalar makes it more number-like;
appending an empty string "" makes it more string-like. But generally it
behaves in a sensible way.
Comparing a string to an integer is a typical gotcha for us ex-Perlers.