in reply to Tracking down an uninitialized value warning

As has been observed many times, constants aren't, variables won't....

I'm suspicious of the "# Some more processing here which is not relevant" section after the more obvious suspects have been eliminated. Have you tried moving the "print Dumper($tref)'" inside your debugging if statement, to see if something in the loop might be sneaking extra entries into %{$tref}? You might also try printing the values of all the variables in the loop and the values of


exists $tref->{$host}{$test}{status}

and


defined $tref->{$host}{$test}{status}
inside that debugging if statement.

Murphy's law of debugging with print statements: the one value that is so redundant and predictable that you can eliminate any need to print it in your sleep is the one that contains the erroneous value. Unless you expected that to happen, in which case it won't.

  • Comment on Re: Tracking down an uninitialized value warning

Replies are listed 'Best First'.
Re^2: Tracking down an uninitialized value warning
by McDarren (Abbot) on Jun 14, 2007 at 08:24 UTC
    I'm suspicious of the "# Some more processing here which is not relevant" section..

    Ok, well for the record - here are the lines that I removed:

    my $icon = "$themepath/$status.gif"; my $testdetails = "/bb/html/$host.$test.html"; print qq(\t<th><a href="$testdetails">), qq(<img src="$icon" border="0" alt="$status" $iconsize title="$test +: $status since $duration ago">), qq(</a></th>\n);
    Basically, I was getting a warning anytime I tried to use $status, obviously because it was undefined.

    Anyway, since posting earlier I've been out for lunch and cleared my head a bit and just taken another look at it. And I've found that if I change the conditional in the if statement to:

    if (defined $tref->{$host}{$test}{status}) {
    ...the warnings disappear.

    Although this has solved my immediate problem, I'm still puzzled as to why..

    defined $tref->{$host}{$test}
    ..returns true in this case, yet
    defined $tref->{$host}{$test}{status}
    ..returns false - when I know for a fact (from the dumper output) that $tref->{$host}{$test} does not exist.

    Thanks for your feedback :)