#!/bin/perl --


use strict;                  

print "Content-Type: text/html\n\n";
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fi\" lang=\"fi\">
  <head>
     <title>lomake</title>
  </head>
 <body>";

print "<table border=\"2\">";

my $ilmo = 'ilmoittautumiset.txt';
open(F,$ilmo);
my @lines = grep(/^\w/,<F>);


close F;
my $line;
foreach $line (@lines) {
  my @r = split(/\t/,$line);
  $line = \@r;
}

print
"<tr><td>Nimi</td><td>Sukunimi</td><td>Opiskelijanro</td><td>email?</td><td>mail1</td><td>mail2</td><td>pääaine</td><td>HarkkaR</td></tr>\n";

foreach my $line (@lines) {
  print "<tr>";
  for (my $i=0; $i<=$#$line; $i++) {
    if ($#$line<7 && $i==$#$line){
      for($i;$i<=7;$i++){
          print "<td>-</td>";}
      print "\n"}
    else{
    print "<td> $$line[$i] </td>";}
  }
  print "</tr>";
}

print "</table>";
print "</body></html>";
