summaryrefslogtreecommitdiffstats
path: root/scripts/csvtodocbooktable.pl
blob: 4ea082ef40c8313367742488e2c3e7c84df59ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl

my $file = shift or die "usage $0 <filename>";

open( IN, "<$file") or die "cant open $file";

@headers = split(/,/,<IN>);

printf('<table frame="all">
        <title>%s</title>
        <tgroup cols="%i" align="char" charoff="50" char=".">
        <thead>
        <row>', $file, scalar(@headers));

foreach $row (@headers)
{
    print "<entry>$row</entry>\n";
}

print "</row>
       </thead>
       <tbody>";

while(<IN>)
{
    print "<row>\n";
    $i = 0;
    @headers = split(/,/, $_);
    for $row (@headers)
    {
	if ($i > 2)
	{
	    printf("<entry align='right'>%.2f</entry>\n", $row);
	} else {
	    print "<entry>$row</entry>\n";
	}
	$i++;
    }
    print "</row>\n";
}

print "</tbody>
       </tgroup>
       </table>";