2 ###############################################################################
7 join_lines_if_short - program for joining some adjacent lines from stdin or one
12 B<join_lines_if_short> [options...] [text files...]
16 B<join_lines_if_short> is used to join adjacent lines from stdin or one or more
17 files, trimming trailing line feeds and carriage returns, and sending the output
18 to stdout. Lines are only joined if the first line is short the expected number
23 B<join_lines_if_short> understands the following optional arguments:
29 Show this documentation.
33 B<join_lines_if_short> will use the specified delimiter <d> for determining the
34 column count for each line. The default is to assume tab as the delimiter.
36 =item --join_delimiter=<d>
38 B<join_lines_if_short> will use the specified delimiter <d> when joining lines.
39 The default is to use no delimiter.
43 B<join_lines_if_short> will expect each line to contain <n> columns. If a line
44 has fewer than <n> columns, then this is the trigger for joining that line with
45 the next line. The new line will be reconsidered and potentially joined with
46 the next line and so on.
51 ###############################################################################
59 my $join_delimiter = "";
63 'delimiter=s' => \$delimiter,
64 'join_delimiter=s' => \$join_delimiter,
65 'columns=s' => \$colcount,
68 pod2usage(-verbose => 2) if $help || ! defined $colcount;
71 while (my $line = <>) {
73 if ($line_buffer eq '') {
76 $line_buffer = "$line_buffer$join_delimiter$line";
78 my @f = split /$delimiter/, $line_buffer, -1;
79 if (scalar(@f) >= $colcount) {
80 $line_buffer =~ s/\x0D//g; # strip embedded carriage returns
81 print "$line_buffer\n";
85 if ($line_buffer ne '') {
86 print "$line_buffer\n";