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
Quote:
PatientID = 1
PatientName = "Fred Smith"
or
Quote:
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