From: "Jason Frisvold" <Jason.Frisvold@corp.ptd.net> > Judging from the subject lines coming across the list today, I think > I'm gonna toss this question out there and then duck and cover... :-) We do not shoot at people here. Even if they do provide the missile address. ;-) > Question #1. > > When I'm writing code, I want to be able to view as much output as > possible so I can trace through everything and ensure that it is, > indeed, running correctly. I've gone as far as writing my own debug > module that uses "levels" and outputs everything in color. > (Term::ANSIColor is a lot of fun to play with)... One major side > effect of this is that my code will begin to run slower due to all of > the debugging... > > So, the obvious answer is to turn off the debugging. However, even > with my magic "debug off switch" (see below for a better explanation), > the calls to the debug routines are still being made. Is there any > sort of #IFDEF that can be done in perl, or do I actually have to > comment out (or remove) each call? > > My magic "debug off switch" is nothing more than a simple if/then > statement. It works on the principle that if $IDebugLevel is a > positive integer greater than 0, then I want to debug. You may mark them somehow and then process your script with something that'll comment them out or strip them entirely. Like http://Jenda.Krynicky.cz/perl/mversion.pl.txt > Question #2. > > Relating to the debugging, there are several instances where I have > variables that are only defined based on the definition of other > variables that exist elsewhere. Kind of like : > > sub dummy { > if ($a == 10) { my $b = 0; } > } > > $b is a local variable, so whenever the subroutine is exited, $b > vanishes into the ether. In this case the difference is not visible, but still ... please keep in mind that the scope of a variable is a block, not a subroutine! So sub foo { if (1 > 2) { my $x = 1; } print "\$x=$x\n"; } foo(); will NOT print $x=1 I hope you DO use strict; > The problem is that I have $b in several > debug statements because I want to see it when it's used, but I don't > want to have to create a huge if/then structure to determine what > variables are being used. No you cannot acces a lexical variable (declared with my()) outside its scope. The only kind-of exception are closures ... subroutines defines inside the variable's scope and thus able to access it later. But that's not what you want. Jenda =========== Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- meThread Previous | Thread Next