in reply to Mysterious the ways: == and eq

Perl is not typeless. It's only that its types are easily (and in many cases automatically) converted from one to another.

It is precisely because of this flexibility that you need different comparison operators. Because a scalar could be interpreted as both a number and a strings, you need to tell perl which basis you want to compare.

Let's say you have $a="1" and $b="000001". Numerically they are the same, but for the purposes of your application those leading zeros could be very important. Because perl has no way of knowing how you want to compare those two variables, you need to tell it by using the appropriate comparison operator.

--ZZamboni

Replies are listed 'Best First'.
RE: RE: Mysterious the ways: == and eq
by rjimlad (Acolyte) on May 25, 2000 at 23:52 UTC
    Well said. Although the language is typeless, it is critical that logical query expressions be type-specific. For example, it might be critical to tell if a string is, exactly, "1.0" (eg. for a version number). Of course, you can use /^1\.0$/ (I think that's right :) ) but that's an inefficient approach. For efficiency's sake, 'eq' is needed, and 'gt' and 'lt' have quite different meanings to > and <. In perl, "1.2" > "1a", but "1.2" lt "1a". If I remember correctly :)