This note returns to the problem I sent to Beginner's Digest on March 3rd, 
and to which Errin Larsen kindly replied in 
issue 2478.

Here is a direct copy of a small part of one of the functions in a program 
which worked fine for months until about two weeks ago (and which has both 
"use strict;" and "use warnings;" at the top):

############  START OF CODE COPIED FROM PROGRAM
unless (defined $CurrentTime) {
        print GlobalVerbosePrintout "\nCurrentTime is not defined\n";
        $debug03MARCH = 1;
}

unless (defined $$lastTime) {
        print GlobalVerbosePrintout "\nlastTime is not defined\n";
        $debug03MARCH = 1;
}

$debug03MARCHlogical = $CurrentTime > $$lastTime;

unless (defined $debug03MARCHlogical) {
        print GlobalVerbosePrintout "\ndebug03MARCHlogical is not 
defined\n";
        $debug03MARCH = 1;
}

if ($debug03MARCH) {
        print "\n\nStopping for debugging.  See the verbose output 
file.\n\n";
        exit;
}

# if ($CurrentTime > $$lastTime) {
if (defined($debug03MARCHlogical)  && $debug03MARCHlogical > 0) {
############  END OF CODE COPIED FROM PROGRAM

Note:  all variables were declared before this block of code, and the 
variable $debug03MARCH was explicitly set equal to zero before this block 
of code.


When the program is run, the following warning appears:

############  START OF WARNING MESSAGE
Use of uninitialized value in string eq at Analysis_tool_V2p6.txt line
        1276, <myFileHandle> line 207 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a 
mistake.
    To suppress this warning assign a defined value to your variables.
<snip>
############  END OF WARNING MESSAGE

Details:

1.  The program ran to completion, rather than stopping with my error 
message "Stopping for debugging.  See the verbose output file."   I 
interpret this to mean that the variables $CurrentTime, $$lastTime, and 
$debug03MARCHlogical are all defined in the three "unless (defined ...)" 
tests.

2.  Line 1276 (the source of the warning message) is the last line in the 
code snippet quoted above.

3.  The same warning message appears when I use the test "if ($CurrentTime 
> $$lastTime)" in line 1275 rather than the debugging version of the test 
in line 1276.

4.  The input data file looks correct.  In particular, the time entry in 
every single record is a real number.

5.  The output is correct when compared with the output when I 
hand-simulate the algorithm (which I would not be able to carry to 
completion if data were missing).

So my questions are:

A.  How can each variable be defined in the "unless (defined ...)" tests, 
but then be declared "uninitialized" in the last line of code quoted 
above?

B.  Aren't "defined" and "initialized" supposed to be equivalent for a 
properly declared variable? (Perhaps this is the gap in my understanding.)

Thanks,
Walt Poor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


  • Undefined vs uninitial... Walter A Poor Jr

Reply via email to