Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hash Key Disappearance 1

Status
Not open for further replies.

Laugman

Programmer
Jul 30, 1999
2
US
I've inherited the following perl code fragment....

1 %Returned = dbPrepare( %Input );
2 if ( $Returned{nStatus} == 0 ) {
3 %Input = ( nDbCursor => $Returned{nDbCursor} );
4 %Returned = dbExecute( %Input );
5 }
6 if ( $Returned{nStatus} == 0 ) {
7 # FINISH CURSOR
8 %Input = ( nDbCursor => $Returned{nDbCursor} );
9 %Returned = dbFinish( %Input );
10 }
11 # SET PROPER RETURN VALUES IF ALL WAS OK
12 if ( $Returned{nStatus} == 0 ) {
13 %Returned = (
14 nStatus => 0,
15 nReturnCode => 0,
16 sReturnDesc => "erLogDataError: Successful"
17 );
18 }
19 return( %Returned );

My environment: AIX 4.3.3, perl 5.004_04

The subroutine dbPrepare (line 1) returns a hash table with 4 keys (nStatus, nReturnCode, sReturnDesc, and nDbCursor).

The subroutine dbExecute (line 4) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).

The subroutine dbFinish (line 9) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).

I haven't been able to detect a pattern, yet, but sometimes the value of nDbCursor (on line 8) is null. If it happened every time, I would deduce that the key nDbCursor became undefined after the execution of dbExecute. Shouldn't the key nDbCursor still be available within the hash table Returned after the execution of dbExecute (and dbFinish)?

As a fix, I am planning to save the value of nDbCursor in a variable after executing dbPrepare and using the variable for the resetting of the hash Input. I'm trying to understand why this code sometimes works and sometimes fails. Any enlightenment would be greatly appreciated.

Thanks.
 
nDbCursor is just a bareword hash key. Do you mean
that $Returned{nDbCursor} is Null?

Line 1 sets %Returned much the same as the following:
Code:
 %Returned = ( nStatus => someval,
               nReturnCode => someval,
               nReturnDesc => someval,
               nDbCursor => someval
             );

Line 4 (if executed) sets %Returned much like:
Code:
 %Returned = ( nStatus => someval,
               nReturnCode => someval,
               nReturnDesc => someval
             );
If the Line 4 statement has been executed, then
%Returned{nDbCursor} should be undefined. The
assignment in Line 4 is setting the entire hash,
not just reassigning to $Returned{nStatus},
$Returned{nReturnCode}, and $Returned{nReturnDesc}
All the old hash keys and values are tossed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top