#! /usr/bin/perl -w
##
## Oldham, Jeffrey D.
## 2000May08
## CS3352

## Prepare a \LaTeX Table

## Given a table specified by a file with
##	1. one table line per file line
##	2. exactly one tab separating each column
##	3. the same number of columns per line
##	4. comments on lines by themselves starting with a '%'
## produce a corresponding \LaTeX\ tabular environment.

## Run using a command line:
## ./prepareTable.pl sampleTable

$nuColumns = -1;
while (<>) {
  if (/\s*%/) {			# comment line
    print;
  }
  else {
    chomp;
    (@foo) = split(/\t/);
    if ($nuColumns < 0) {
      $nuColumns = scalar @foo;
      print("\\begin{tabular}{");
      for ($i = 0; $i < $nuColumns; ++$i) {
	print("l");
      }
      print("}\n");
    }
    print(join(" &\t", @foo), " \\\\\n");
  }
}
print("\\end{tabular}\n");
