-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtbl2ghwiki
executable file
·45 lines (43 loc) · 972 Bytes
/
tbl2ghwiki
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 $n=0;
my $len;
my $hlen;
while ($ARGV[0] =~ m@^-@) {
my $opt = shift @ARGV;
if ($opt eq '--header'){
$n = 1;
@vals = split(/,/,shift @ARGV);
$len = scalar(@vals);
print '|'.join('|',@vals)."|\n";
@vals = map {"---"} @vals;
print '|'.join('|',@vals)."|\n";
}
}
while(<>) {
chomp;
if ($n==0 && m@^\#@) {
s@^\#@@;
}
my (@vals) = split(/\t/,$_);
@vals = map {s@\|@, @g; $_} @vals;
@vals = map {s@^\>@`>`@g; $_} @vals;
if (!$hlen) {
$hlen = scalar(@vals);
}
while (scalar(@vals) < $hlen) {
push(@vals, '');
}
print '|'.join('|',@vals)."|\n";
$nulen = scalar(@vals);
if ($n > 0) {
if ($len ne $nulen) {
print STDERR "MISMATCH: $len != $nulen\n";
}
}
$len = $nulen;
if ($n ==0) {
@vals = map {"---"} @vals;
print '|'.join('|',@vals)."|\n";
}
$n++;
}