untitled

(ff) #1

10.1 Text Transformations 209


print("Health Study Data\n\n");
$count = 0;
$bmisum = 0;
$bmisumsq = 0;


while (<>) {
$month = substr($, 0, 2) + 0;
$day = substr($
, 2, 2) + 0;
$yr = substr($, 4, 2) + 0;
$year = 1900 + $yr;
$year = 2000 + $yr if $yr < 20;
$bmi = substr($
, 6, 8) + 0;
$status = "normal";
$status = "obese" if substr($, 14, 3) + 0 > 0;
$status = "overweight" if substr($
, 17, 3) + 0 > 0;
$height = substr($, 20, 3) + 0;
$wtkgs = substr($
, 23, 8) + 0;
$wtlbs = substr($_, 31, 3) + 0;
print("$month/$day/$year $bmi $status");
print(" $height cm $wtkgs kg $wtlbs lb\n");
$count = $count + 1;
$bmisum = $bmisum + $bmi;
$bmisumsq = $bmisumsq + $bmi ** 2;
}


print("\n");
print("Number of records: $count\n");
$bmimean = $bmisum / $count;
print("Average BMI: $bmimean\n");
$bmivar =
($bmisumsq - $count * $bmimean 2) / ($count - 1);
print("BMI Variance: $bmivar\n");
$bmisd = $bmivar
0.5;
print("BMI Standard Deviation: $bmisd\n");


Program 10.3 Computation of statistical information
Free download pdf