×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hash Key Disappearance

Hash Key Disappearance

Hash Key Disappearance

(OP)
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.

RE: Hash Key Disappearance

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:

 %Returned = ( nStatus => someval,
               nReturnCode => someval,
               nReturnDesc => someval,
               nDbCursor => someval
             );


Line 4 (if executed) sets %Returned much like:

 %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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close