CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Nov 2006
    Posts
    103

    having trouble with a hash of key, array...

    I have a hash table that is patient id, patients names
    In my data sometimes the patients names are entered in differently but they are the same patient.

    A patient might be listed as

    PatientID = 1
    PatientName = "Fred Smith"
    or
    PatientID = 1
    PatientName = "F Smith"

    so what I need is a hash of PatientID, ("Fred Smith", "F Smith")

    Code:
            if (exists($hash{$pid})) {
    
                @foo = $hash{$pid};
                @bar = grep(/$pname/, @foo);
                $size = @bar;
                if ($size == 0) {
                   push(@foo, $pname);
                   $hash{$pid}=@foo;  // I think this line is wrong... because its storing the size of the array rather than the contents...
                }
             } else {
                $hash{$pid}=($pname);  // This is a new patient id and therefore a new name (array of 1 element).  This is probably wrong too...
             }
    The above code looks to see if the pid exists in the hash table.
    If it does then it checks if the patient name being added has already been added to the list of patient names.
    If it hasn't then its added.

    However when I print out the hash table at the end I get something like
    PatientID
    2
    Last edited by PeejAvery; July 22nd, 2013 at 09:31 PM. Reason: Added code and quote tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured