#!/usr/bin/perl #bmi.cgi - calculate Body Mass Index #written 6/5/1998 by Rich Gibson Rich@chilidog.com #Additional comments added 1/10/2001 use CGI qw(:standard); $query = new CGI; #All get/post method variables now exist as $R:: $query->import_names('R'); print "Content-type: text/html\n\n"; #Open a template file, should be index.htm #hideously dangerous, to accept our template file name from input! open IN, "$R::file" or print "Could not open input file $epi ... sorry"; #read the file, a line at a line, and look for substitution variables #I 'now' (1/10/2001) have a much stronger template mechanism. while (){ if (//){ #print "We found a variable... it is: |$1|"; if ($1 eq "bmi") { $bmi = ($R::weight*703) / ($R::height*$R::height); $bmi = sprintf "%4.1f", $bmi; print "$` $bmi "; } if ($1 eq "idealweight") { $idealweight = (25*($R::height * $R::height))/703; $idealweight = sprintf "%4.1f", $idealweight; s/]+>/$idealweight/; print $_; #assume we want a table after that... if ($bmi > 20) { @bmi =""; print ""; for ($i=int $bmi; $i >= 20; $i--){ $w = ($i*($R::height * $R::height))/703; $w = sprintf "%4.1f", $w; @bmi[$i] = $w; print "\n"; } print ""; for ($i=int $bmi; $i >= 20; $i--){ print "\n"; } print "
BMI$i
Weight$bmi[$i]
"; } } } elsif (/name\s*=\s*"([^"]+).*value=""/) { #the substitutions #this craps all name/value lines that have value="" #then check for our parameters-> height and width if ($1 eq "weight") { s/value=""/value="$R::weight"/; } if ($1 eq "height") { s/value=""/value="$R::height"/; } print "$_"; } else { print $_; } } exit;