in reply to Double blank lines to single blank line
my $lineend = qr/\n\r|\r\n|\n|\r/; $data =~ s/($lineend){3}/$1$1/sg;
This defines a regular expression which detects the end of a line. It first checked for a newline - carriage return combination. If this is not found it checks for a carriage return - newline combination. If neither of these two combinations are found, then it checks for a newline or a carriage return.
The next expression assumes you have your entire file in $data. It then replaces 3 end-of-line combinations (2 blank lines) with 2 of them (2 end-of-line combinations will produce a single blank line).
Actually, if the blank lines might contain whitespace, then you could consider the following expression instead:
$data =~ s/($lineend)\s*($lineend)\s*($lineend)/$1$1/sg;
(Regexps tested ok on linux).
|
|---|