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

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.