• sugar_in_your_tea@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 days ago

    the length of the array is coerced to be a string and then the length of that string is returned.

    it’s the string coercion that I have a problem with. I’d much rather have an error than have things silently be coerced to different types.

    • palordrolap@fedia.io
      link
      fedilink
      arrow-up
      2
      ·
      3 days ago

      Perl was originally designed to carry on regardless, and that remains its blessing and curse, a bit like JavaScript which came later.

      Unlike JavaScript, if you really want it to throw a warning or even bail out completely at compiling such constructs (at least some of the time, like this one) it’s pretty easy to turn that on rather than resort to an entirely different language.

      use warnings; at the top of a program and it will punt a warning to STDERR as it carries merrily along.

      Make that use warnings FATAL => "syntax"; and things that are technically valid but semantically weird like this will throw the error early and also prevent the program from running in the first place.