develooper Front page | perl.beginners | Postings from April 2002

Debugging and 'uninitialized value in concatenation' question

Thread Next
Jason Frisvold
April 25, 2002 12:24
Debugging and 'uninitialized value in concatenation' question
Message ID:
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...  :-)

I have 2 actual questions.  I'll try to be as specific as possible..

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

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.

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.  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.

So, the general question becomes, how should variables like this be
handled?  Should I be initializing them every iteration even if they go
unused, or should I be using some sort of defined() statement?  What is
the "proper" way to handle this in perl?  If this was C, I would have to
say that the variables are declared each time...  I'm just curious if
there's a better way to handle this in perl...


Jason H. Frisvold
Senior ATM Engineer
Engineering Dept.
CCNA Certified - CSCO10151622
"I love deadlines.  I especially like the whooshing sound they make as
they go flying by." -- Douglas Adams [1952-2001]

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About