#!/usr/bin/perl

$bio_file = "misnorcal.txt";

open(FILE, "< $bio_file");
@lines = <FILE>;
close(FILE);

foreach $line (@lines) {
   chomp $line;
   if (($line eq "")) { next; }

   $line =~ s/'/&#39;/g;
   ($key, $lname, $fname, $dob, $birthplace, $entered_army, $discharged_army, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $notes1, $notes2, $honor1, $honor2, $honor3, $oral_history, $auto, $ques, $bio, $photo, $article, $narrative) = split(/\t/, $line);

   $result = &get_biography($narrative);

   print "UPDATE veterans SET biography = \"$result\" WHERE veteran_id = $key;\\g\n";
}

sub get_biography {
   my $bio = $_[0];
   my $res = "";

   if ($bio) {
      $bio =~ s/.txt/.html/g;
      $bio =~ s/ //g;

      open(FILE, "< $bio");
      @bio_lines = <FILE>;
      close(FILE);

      foreach $bio_line (@bio_lines) {
         $bio_line =~ s/"/&quot;/g;
         $res .= $bio_line;
      }
   }

   return $res;
}


