#!/usr/bin/perl -s
$attribs = 'border=1';
# tsv2html - filter tab-separated text into an HTML table
# Steve Kinzler, kinzler@cs.indiana.edu, Mar 07
# http://www.cs.indiana.edu/~kinzler/home.html#unix
die "usage: $0 [ -t ] [ -T ] [ -l ] [ -L ] [ file ... ]
-t highlights the first row as titles
-T highlights the second row as titles
-l remove := labels on each field value
-L highlight first row := labels as a new title row\n" if $h;
print '
\n";
while (<>) {
chop;
@_ = split(/\t/);
if ($L && $. == 1) {
print '';
foreach (@_) {
$lbl = /(.*):=/ ? $1 : '';
print "| ", &htmlencode($lbl), " | ";
}
print "
\n";
}
print '';
$td = ($t && $. == 1 || $T && $. == 2) ? 'th' : 'td';
foreach (@_) {
s/.*:=// if $l;
print "<$td>", &htmlencode($_), "$td>";
}
print "
\n";
}
print "
\n";
###############################################################################
sub htmlencode {
local($_, $mlm) = (join('', @_), $*);
$* = 1;
s/&/&/g;
s/</g;
s/>/>/g;
$* = $mlm;
return $_;
}