in reply to Re: Overriding Global Variables
in thread Overriding Global Variables

Hi haukex,

The idea was that the "debug" function is enabled or disabled in accordance to the module that uses it, effectively enabling a clean and easy way to debug different modules as part of a very large flow, involving many. One "debug" variable doesn't suit this purpose, and also adds in the clutter of setting and resetting the variable whenever needed.

Replies are listed 'Best First'.
Re^3: Overriding Global Variables
by LanX (Saint) on Nov 19, 2017 at 21:14 UTC
    > clutter of setting and resetting the variable whenever needed.

    That's where you use local to change the flag.

    The old value will be reset automatically after the dynamic (runtime) scope is left.

    edit

    FWIW you could additionally have a lexical variable with my which is block scoped and check it using PadWalker

    You need to decide which flag takes precedence though, I'd say my over our

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^3: Overriding Global Variables
by haukex (Archbishop) on Nov 20, 2017 at 09:15 UTC
    the "debug" function is enabled or disabled in accordance to the module that uses it

    I see, in that case I would concur with karlgoethebier and I think an OO approach is probably best - each module can get an object with an individual debug flag. And looking into existing logging modules, as 1nickt said, makes sense before you re-invent that wheel.