• @nyan@lemmy.cafe
    link
    fedilink
    English
    32 days ago

    That’s because Perl doesn’t do operator overloading in general. Even the equality operator is different for strings (eq instead of ==). As a language, it may look pretty weird and lack some modern features, but the underlying design is surprisingly intelligent and consistent in many ways.

    • palordrolap
      link
      fedilink
      12 days ago

      Not strictly true.

      Perl’s default bitwise operators do differentiate between numbers and strings that look like numbers in a way that addition doesn’t*, and the readline/glob operator <> does different things depending on what (if anything) is between the signs.

      There’s also the whole overload pragma for objects, which doesn’t affect default data types, but if you’re sufficiently perverse, you can define a String class that uses ‘+’ like JavaScript.

      * in 2015, they added new operators so that those and the original operators don’t overload and have only one specific purpose if the bitwise pragma Edit: feature is turned on. You might know all this already though.