2 ###############################################################################
7 join_lines - program for joining adjacent lines from stdin or one or more files
11 B<join_lines> [options...] [text files...]
15 B<join_lines> is used to join adjacent lines from stdin or one or more files,
16 trimming trailing line feeds and carriage returns, and sending the output to
17 stdout. Arguments are used to define the criteria and exact behavior.
21 B<join_lines> understands the following optional arguments:
27 Show this documentation.
31 B<join_lines> will use the specified delimiter <d> to separate joined lines. The
32 default is to use no delmiter when joining lines.
36 This will cause B<join_lines> to join every <n> lines into one line.
38 =item --record-separator=<s>
40 This will cause B<join_lines> to immediately start a new line when it encounters
41 a line solely containing <s>. That line itself will not otherwise be used. This
42 argument may be used in conjunction with --lines, but probably should not be. :)
44 =item --record-separator-empty-line
46 This works like --record-separator, but is a way to define an "empty" line as
47 being the record separator.
52 ###############################################################################
62 my $record_separator_empty_line;
65 'delimiter=s' => \$delimiter,
66 'lines=s' => \$linecount,
67 'record-separator=s' => \$record_separator,
68 'record-separator-empty-line' => \$record_separator_empty_line,
71 pod2usage(-verbose => 2) if $help;
77 print join($delimiter || '', @lines) . "\n";
82 while (my $line = <>) {
84 $line =~ s/[\r\n]+$//g;
85 if (defined $record_separator_empty_line && $line eq '') {
87 } elsif (defined $record_separator && $line eq $record_separator) {
89 } elsif (defined $linecount && $count == $linecount) {
92 } elsif (! defined $linecount && ! defined $record_separator && ! defined $record_separator_empty_line) {
93 print "$line\n"; # passthru when given no arguments
98 if (scalar(@lines) > 0) {
99 print join($delimiter || '', @lines) . "\n";