in reply to Single newline removal when line exceeds x characters
And the output is as expected -use strict; my $prev_length = 0; my $threshold = 40; my $first_line = 1; while (<DATA>) { chomp; # s/^\s+//g; # s/\s+$//g; my $curr_length = length($_); if ($prev_length > $threshold && $curr_length > 0) { print " "; } elsif ($first_line) { $first_line = 0; } else { print "\n"; } print "$_"; $prev_length = length($_); } print "\n"; __DATA__ This is a longish line whose linebreak should be removed so that this line runs together with it. The preceding double linebreak should be conserved. This little line and this one should stay separated.
This is a longish line whose linebreak should be removed so that this +line runs together with it. The preceding double linebreak should be conserved. This little line and this one should stay separated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Single newline removal when line exceeds x characters
by tachyon (Chancellor) on Oct 20, 2003 at 07:51 UTC | |
by Roger (Parson) on Oct 20, 2003 at 08:04 UTC |