WIP: uniproc
[hband-tools.git] / tabdata / td-trans
blob14025ef200d26a23a180ba57b383fcb247ff5811
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 td-trans - Transform whitespace-delimited into TAB-delimited lines ignoring sorrounding whitespace.
9 =head1 OPTIONS
11 =over 4
13 =item -m, --max-columns I<NUM>
15 Maximum number of columns.
16 The I<NUM>th column may have any whitespace.
17 By default it's the number of fields in the header (first line).
19 =back
21 =cut
23 $OptMaxColumns = undef;
24 %OptionDefs = (
25 'm|max-columns=i' => \$OptMaxColumns,
28 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
29 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
31 while(my $line = <STDIN>)
33 chomp $line;
34 $line =~ s/^\s*//g;
35 $line =~ s/\s*$//g;
37 if($. == 1 and not defined $OptMaxColumns)
39 # the first line considered header,
40 # and the number of fields dictates (at most) how many fields are there in the rest of the stream.
41 $OptMaxColumns = scalar split /\s+/, $line;
44 my @Fields = split /\s+/, $line, $OptMaxColumns;
46 print join($FS, @Fields).$RS;