in reply to How to remove newline characters at the end of file
What have you tried so far?
When you read an empty line, you can't know yet whether to print it. So you need something along the lines of
my $newlines = 0; while (<$file>) { if (/^$/) { $newlines++; } else { print "\n" x $newlines; print; $newlines = 0; } }
(untestested).
update: closed regex, ww++.
|
|---|