On Sun, Dec 10, 2000 at 07:26:38PM -0800, Bill Moseley wrote:
> Just how smart is the compiler?
[snip]
> use constant DEBUG_TEMPLATE          => 1;
> use constant DEBUG_SESSION           => 2;
> use constant DEBUG_REQUEST           => 4;
> use constant DEBUG_QUERY             => 8;
> use constant DEBUG_QUERY_PARSED      => 16;
> 
> my $debug = DEBUG_REQUEST|DEBUG_QUERY;
> 
> warn "query = '$query'\n" if $debug & DEBUG_QUERY;

Not quite that smart. It has no idea if `$debug' will have changed by
the time you're asking about it. However, if you make `$debug' into a
constant, it will work (where "work" is defined as "optimize out the
conditional").

  use constant FOO => 1;
  use constant BAR => 2;
  use constant FOOBAR => FOO|BAR;
  warn "baz" if FOOBAR & FOO;

> use constant DEBUG_TEMPLATE          => 0;  # OFF
> use constant DEBUG_SESSION           => 1;  # ON
> use constant DEBUG_REQUEST           => 0;
> use constant DEBUG_QUERY             => 1;  # ON
> use constant DEBUG_QUERY_PARSED      => 0;
> 
> warn $query if DEBUG_QUERY || DEBUG_QUERY_PARSED;

This will also work, but I like the first approach better. It allows you
to factor out the component you want to debug.

-dlc

Reply via email to