flexvault has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I've been working on a pure perl database and the following code gets a warning message ('Use of uninitialized value in hash element at pyrdb.plx line 1179.') after about 2 million calls to the subroutine.
Line 1179 is marked with the '*' in column 1.$$db{CurrentKey} = $SavSubtree[$curuser][$$db{RSubtreeno}]; $$keyptr = $$db{CurrentKey}; my $datapos; * if ( defined $RSubtree{$curuser}{$$keyptr} ) { $datapos = $RSubtre +e{$curuser}{$$keyptr}; } if ( ( defined $$keyptr )&&( defined $datapos ) ) { $ret = &GetDataRecord( $db, $keyptr, $dataptr, $datapos ); if ( $ret == TRUE ) { flock( $$db{btree}, LOCK_UN ); return("") +; } }
The warning doesn't affect the results, since I'm testing for the record being in cache, and if not it falls through to check for the record on disk. But the warning message is an irritation.
I've tried several different ways of re-writing the line but I still get the warning message twice in 4 million calls to the routine.
Is there another way of writing the line to eliminate the warning?
UPDATE: I solved the problem. The warning message was correct. In database programming, you try to balance the trees. At the tree extremes, I was incorrectly testing for the end, and calling the routine with undefined data. I solved it by putting a 'print STDERR' in the routine, and then calling the script with redirecting the STDERR to a file. The error was then obvious. Thanks to everyone's help and some of the answers were very interesting.
Thank you
"Well done is better than well said." - Benjamin Franklin
|
|---|