in reply to Overriding Global Variables

This

  our DEBUG_FLAG =1;

belongs to the importing package, so you need to know its name

TIMTOWTDI

Sorry, no code now, I'm on mobile at the moment and can't test.

NB: DEBUG_FLAG has no sigil in your example! Please post only valid code!

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

Replies are listed 'Best First'.
Re^2: Overriding Global Variables
by Mano_Man (Acolyte) on Nov 19, 2017 at 16:28 UTC
    Can the caller package and its global variables be accessed without it being known to the "Debug" module via 'use' or 'require? I'd love to see an example if you get around to it. Thanks LanX.
      Here a simple demonstration without importing ( ::debug is short for main::debug )

      use strict; use warnings; use Carp; package main; sub debug { my ($pkg) = caller; { no strict 'refs'; return unless ${ "${pkg}::DEBUG_FLAG" }; } carp "@_"; } package My_First; our $DEBUG_FLAG = 1; ::debug( "Print " . __PACKAGE__ ); # prints package My_Second; our $DEBUG_FLAG = 0; ::debug( "Print " . __PACKAGE__ ); # doesn't print

      Print My_First at d:/Users/RolfLangsdorf/pm/pm_debug_caller.pl line 23 +.

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

      Update

      improved code with Carp to report file and line from callers perspective.