Hey all.
 
I need to trace / debug a CGI script which basically involves lots of
'print DEBUG_FH'.
 
I noticed the existence of the Devel::Trace module which allows you to
trace your
perl script to STDERR
 
eg,
 
perl -d:Trace  myprog.pl
 
However, since my program is a CGI, I've come across a few problems.
 
(1)  The perl -d:<module> construct only works for Devel::Module
modules.
(2)  The Devel::Trace module only traces to STDERR
(3)  How do I launch my CGI with '-d' and have my tracing go to a log
file?
 
 
To solve this, I did the following:
 
(1)  Implement a local DB::DB function which performs the tracing to 
module mytrace;
 
sub DB::DB()
{
    ... trace code which traces to $_TRACE_FH  if $_TRACE
}
 
sub trace_to
{
    open( $_TRACE_FH, "$logfile");
   $_TRACE = 1;
}
 
(2) Start debugging via the command line
 
#!perl -d -w
 
(3) Configure APACHE to disable the perl interactive debugger
 
SetENV    PERL5DB    ""
 
 
This works, however it would be neater if there was a command in perl
where
I could enable 'debug' and hence start tracing from a point. While not
wasting
CPU cycles when debugging isn't enabled.
 
PS.  I tried printing '$^D' but it was always zero. (not undef)
changing it 
       obviously didn't have the effect I could hope for.  I presume the
'$^D' is
       relative to the -D flag, not the -d flag.
 
Cheers.
David
 
 
 
 

Reply via email to