Re: defined on hash value does not work in my code :(



saffy wrote:
Sorry, posted too early:-

I have corrected the error and some others, but I still have the
problem:-

Basically, the problem boils down to the following, in the code below:-

this line works:-
$times1[$#times1 + 1] = sprintf "%s",
$db{$months}{$days}{$computernames}{$hours}
          if ($db{$months}{$days}{$computernames}{$hours}
             && $cts == 1);

but this one doesn't:-
$cts++ unless defined($db{$months}{$days}{$computernames}{$next})

It is working. It's just not doing what (I think) you're expecting. The above only increments $cts when $db{$months}{$days}{$computernames}{$next} is *not* defined, but what I think you what is to increment $cts when the hash *is* defined. Try changing the unless to if and see if that helps.


using the debugger shows that $next has the correct value i.e. (when
$hour = 00, $next = 01) but for some reason
$db{$months}{$days}{$computernames}{$next} does not appear to ever
contain a value, even when it should!!

This is probably a silly syntax error on my part or there is something
about nested hashes that I don't understand.

I doubt it as perl would warn you of any syntax errors. You are using warnings, right?
.