in reply to constants in an RE

Use Readonly instead of constant.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: constants in an RE
by haukex (Archbishop) on May 16, 2023 at 07:56 UTC
    Use Readonly instead of constant.

    Years ago I started doing exactly that, only to discover strange bugs. I then completely abandoned Readonly, opting to use normal variables in all caps - it gives variables that interpolate and that can be overridden for testing. And since I mostly publish libraries where such variables are typically undocumented package variables, if someone chooses to reach into my package and break something by changing "constants", it's their fault. And yes, this philosophy only works when you don't have many users and those users are programmers...

      The module ReadonlyX claims to be a drop-in replacement for Readonly which fixes many of the bugs and avoids the time penalty. Unfortunately, it is not an exact "drop-in". It may be a good solution to your problem.
      Bill
      > such variables are typically undocumented package variables,

      FWIW: There is an old poor man's trick to make package vars readonly, by assigning refs of literals to globs.

      DB<35> *RO=\5 DB<36> p $RO 5 DB<37> $RO=6 Modification of a read-only value attempted at (eval 51) ...

      HTH! :)

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery