248 10 Transforming with Traditional Programming Languages
print("<HealthStudy>\n");
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;
$weight = substr($_, 23, 8) + 0;
print("<Interview>\n");
print(" <Date>$year-$month-$day</Date>\n");
print(" <BMI>$bmi</BMI>\n");
print(" <Status>$status</Status>\n");
print(" <Height>$height</Height>\n");
print(" <Weight>$weight</Weight>\n");
print("</Interview>\n");
}
print("</HealthStudy>\n");
Program 10.19 Converting flat file information to XML element content
two elements, one inside the other, that looks like this:
<Main>
<Part id=’p1’>XML Example</Part>
</Main>
except that the Part id and the content of the Part element are obtained from
an input file:
p1:XML Example
One can do this in Perl without templates by using program 10.20.
This program accomplishes the task, but as the transformation task gets
more complicated, it is difficult to understand what is being done by this