SPUG: Debugging methodology (was: How to deal with same name packages?)

Chris Wilkes cwilkes-spug at ladro.com
Tue Jan 15 02:46:13 CST 2002


On Mon, Jan 14, 2002 at 10:08:53PM -0800, Richard Anderson wrote:
> 
> Callers of my modules can activate debug messages using a class variable
> Debug:
> 
> use MyClass;
> $MyClass::Debug = 1;         # or 2 or 3
> $MyClass::DoSomething();
> 
> and in MyClass:
> 
> if (Debug > 0) {
>    print (whatever)
> }
> 
> I usually have two or three debug levels of varying verbosity.  The debug
> messages are written to standard out or the Apache error log for mod_perl
> apps.   The performance impact of checking $Debug is trivial compared to the
> benefits.

If you made Debug a constant then there wouldn't be a performance hit as
it would get optimized away at run/compile time, if my memory of a
recent TPJ article by Sean Burke is correct.

With DEBUG => 3 then you'll have "If (3 > 0) { print }" which will get
optimized to just "print"  Likewise if you had DEBUG => 0 the whole "if
( 0 > 0 ) {}" will get thrown out.

Chris

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list