in reply to Removing double carriage return
I can't see how that could even "kind of works". According to the perlrun description of the -p switch your code provided on the command line is wrapped in:
while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
which deals a line at a time so your regex will never match. For such a multi-line matching regex to make sense you need to slurp the whole file into a string and run the regex on that. The easiest way to do that is write a small script rather than try to shoehorn it into a "one liner". However that gets to be a whole lot more work because you then have to handle things a file at a time instead of using Perl's -i and @ARGV magic in a simple fashion. However, with just a little work we can still use the magic:
use strict; use warnings; my @files = @ARGV; $^I = '.bak'; for my $file (@files) { local $/; @ARGV = $file; while (<>) { s/\n\n/\n/gs; print; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing double carriage return
by dragooneye (Novice) on Aug 22, 2011 at 18:10 UTC |