This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
RE: Mysterious the ways: == and eq
by ZZamboni (Curate) on May 25, 2000 at 21:52 UTC
    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

      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 :)
RE: Mysterious the ways: == and eq
by t0mas (Priest) on May 25, 2000 at 23:13 UTC
    Perl is not typeless,
    it behaves like it does
    so you can type less...

    /brother t0mas
RE: Mysterious the ways: == and eq
by merlyn (Sage) on May 26, 2000 at 01:46 UTC
    Thus was spake...
    For a typeless language...
    Perl is anything but a typeless language.
    • You can't store a hash into an array variable.
    • You can't store an array into a scalar.
    • You can't dereference a hashref as if it was a coderef.
    • ... and so on.
    I don't know where this "typeless" stuff comes from. Perl is very strongly typed. Just because "scalar" is a type that includes things that other languages call "strings", "characters", "numbers", and "references", doesn't mean that "scalar" isn't distinct type!

    -- Randal L. Schwartz, Perl hacker

      sorry to be a pedant, but i figure it's only fair since you tend to be one with respect to Perl (and many including me are grateful for it).

      the word 'spake' is not a past participle, it is only a preterite verb form. it only appears as the head verb in a clause, like so: "Thus spake Fr. Harry G. Monk: Perl is typeless".

      while i agree with you, that perl is a very typed language... the person is complaining not about the inability to compare things of different types... what died here is the comparison of a scalar against a scalar, the system died not because we were comparing different types! The system died because we were comparing the same type, with a different value... that, you have to admit, on some level... seems "bad"
        ok, that's the word i was looking for... orthagonality... language fails the "test" of a good language (according to my programming language theory book) at this point ( the eq == discrepancy) perl is NOT orthagonal...
RE: Mysterious the ways: == and eq
by chromatic (Archbishop) on Jun 06, 2000 at 18:36 UTC
    The reason Perl has things like this (operators that seemingly do duplicate things) is so that Perl hackers can give perl hints as to what the Right Thing is.

    Though it often does the Right Thing even in ambiguous situations (is "001" supposed to be interpreted as a number or a string?), there are occasions when it needs explicit instructions. Things like eq and scalar and so forth let you be sure things are interpreted as you intend.

RE: Mysterious the ways: == and eq
by infoninja (Friar) on May 25, 2000 at 23:46 UTC
    When they both are strings,
    one and zero one differ
    == and eq
RE: Mysterious the ways: == and eq
by Anonymous Monk on May 26, 2000 at 15:37 UTC
    It's precisely because perl is typeless that multiple comparison operators are needed.