in reply to DEBUG redux

To make it global beyond "within the current package":

sub ::DEBUG() { 1; } # Example use: DebugDump( \%hash ) if ::DEBUG();

As for how to do this in Apache, I'd probably just make "use DEBUG;" do this for you and then you can tell Apache to load the DEBUG module when you want this.

Update: But you'll want sub ::DEBUG() { 0; } when you don't want debugging so you probably need two different ways to "use DEBUG". You could have "use DEBUG;" turn on debugging (for easy use in an Apache config). Then "use DEBUG qw/inherit off/;" would only define ::DEBUG() if it hadn't already been defined (in which case it would define it as 0 or 1, depending on whether 'off' or 'on' was the second argument). So any code that uses ::DEBUG() would have the "use DEBUG qw/inherit off/;" near the top so that ::DEBUG() wouldn't try to call a non-existant subroutine.

package DEBUG; use strict; sub import { my $pkg= shift @_; my $default= 1; if( @_ && 'inherit' eq $_[0] ) { return if defined \&::DEBUG; shift @_; $default= 0; } if( @_ && $_[0] =~ /^(on|off)$/ ) { $default= 'on' eq $_[0] ? 1 : 0; shift @_; } if( @_ ) { require Carp; Carp::croak( "Usage: use DEBUG ['inherit',] ['on'|'off'];" ); } eval "sub ::DEBUG() { $default; }; 1" or die $@; } sub unimport { if( 2 < @_ || 2 == @_ && 'inherit' ne $_[1] ) { require Carp; Carp::croak( "Usage: no DEBUG ['inherit'];" ); } import(@_,'off'); }

- tye