I'm very new to Perl and trying to get things to work. I'm working with a dataset that originally looks like this:
ID Intdaymiss Daysobs
2611 . 12
2611 5 28
2612 . 0
2613 0 .
2613 5. 5
2613 17 50
I want to print output to an outfile that looks like this:
ID TotalDM TotalDO 1-DM/DO (ADhash)
2611 5 30 solution
2612 . 0 solution
2613 53 22 solution
The following section worked where I created a hash for DM and a hash for DO to sum the DM and DO per patientid (key).
%dmhash = {};
%dohash = {};
for ($i=1; $i<@id; $i++){
$dmhash{$id[$i]} += $intdaymiss[$i];
$dohash{$id[$i]} += $daysobs[$i];}
foreach my $key (sort keys %dmhash) {
print "$key = $dmhash{$key}\n";}
Now I'm trying to references the hashes to make calculation of a new ADhash (which is the column I'm making the calculation for) but something is wrong with the way I'm referencing the hashes for calculation. Do you know how to fix it and how to print the solution in the form I want?
%adhash = {};
while(@patientid){
if(($dohash{$patientid})=0) {
$adhash{$patientid}=nil;
}
else{$adhash{$patientid} = 1-(($dmhash{$patientid})/($dohash{$patientid}));
}
}
Thanks!
ID Intdaymiss Daysobs
2611 . 12
2611 5 28
2612 . 0
2613 0 .
2613 5. 5
2613 17 50
I want to print output to an outfile that looks like this:
ID TotalDM TotalDO 1-DM/DO (ADhash)
2611 5 30 solution
2612 . 0 solution
2613 53 22 solution
The following section worked where I created a hash for DM and a hash for DO to sum the DM and DO per patientid (key).
%dmhash = {};
%dohash = {};
for ($i=1; $i<@id; $i++){
$dmhash{$id[$i]} += $intdaymiss[$i];
$dohash{$id[$i]} += $daysobs[$i];}
foreach my $key (sort keys %dmhash) {
print "$key = $dmhash{$key}\n";}
Now I'm trying to references the hashes to make calculation of a new ADhash (which is the column I'm making the calculation for) but something is wrong with the way I'm referencing the hashes for calculation. Do you know how to fix it and how to print the solution in the form I want?
%adhash = {};
while(@patientid){
if(($dohash{$patientid})=0) {
$adhash{$patientid}=nil;
}
else{$adhash{$patientid} = 1-(($dmhash{$patientid})/($dohash{$patientid}));
}
}
Thanks!