I would expect the block in the second 'if' statement to be entered because of the undef value but the logs show that it isn't being entered.
sub getcmd{
my $self = $_[0];
if ( $self->_recv == OK ){
push @{$self->{'log'}}, ['NOTICE', "OK"];
return "My command";
}
push @{$self->{'log'}}, ['ERROR', "Did not get OK back"];
return undef;
}
...
if (!($ret = $self->getcmd)){
push @{$self->{'log'}}, ['ERROR', "failed to read after asking for NEXT"];
}
else {
push @{$self->{'log'}}, ['ERROR', "'undef' not detected in next()"];
}
The log file shows:
[Fri May 8 19:25:56 2009]: ERROR: Did not get OK back
[Fri May 8 19:26:02 2009]: ERROR: 'undef' not detected in next()
Any ideas gratefully accepted.
Edit: Sorry, I'd edited down the code to show the basic flow. I should've proofread it a bit better.
- I added the $ret in getcmd() to simulate what happens in the logging function which just prints out the current value of $ret which is a global variable always used to capture return values.
- I'd trimmed down the log messages and missed the extra "back"
Thanks for the suggestions and comments. I hadn't noticed the six second difference in the log timestamps so now I suspect that you're right about the execution sequence being different to what I originally expected.
I'll go back and look again. Guess that's what you get when trying to look at someone else's "average" Perl after a thirteen hour day trying to get things finished for a "must go live on Monday" project!
I didn't write the code and simply inherited it. The code was written by a couple of people who think they don't "need no steenking warnings or stricts".
Imagine 800 lines of Perl and lots of 'ifs' but no else statements! No defensive coding at all! 8-O
One again thanks for your help.
cheers,