Ok, shoot me now... I tried to provide an example and I blew it.. *grin* I realize that the locals are block scope.. I know what I meant, just didn't say it.. :)
I understand that you cannot access a local variable outside it's scope.. Hrm.. ok, try this : sub dummy { my $a; if ($b == 1) { $a = 2; } print "$a\n"; } Now.. If $b is 1, then $a gets set to 2 and everything is great. However, if not, $a stays unintialized (which I believe is null) and I get that 'uninitialized value' error... I think I'm answering my own question, though... always initialize the variable and stupid stuff like this won't happen... --------------------------- Jason H. Frisvold Senior ATM Engineer Engineering Dept. Penteledata CCNA Certified - CSCO10151622 [EMAIL PROTECTED] --------------------------- "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." -- Albert Einstein [1879-1955] -----Original Message----- From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 25, 2002 4:17 PM To: [EMAIL PROTECTED] Subject: Re: Debugging and 'uninitialized value in concatenation' question From: "Jason Frisvold" <[EMAIL PROTECTED]> > 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 =========== [EMAIL PROTECTED] == 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. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]