in reply to Re: constants in an RE
in thread constants in an RE

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...

Replies are listed 'Best First'.
Re^3: constants in an RE
by BillKSmith (Monsignor) on May 16, 2023 at 21:57 UTC
    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
Re^3: constants in an RE
by LanX (Saint) on May 16, 2023 at 15:28 UTC
    > 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