in reply to replace \n with space to join indented lines
-p processes the file one line at a time, while both of your regexp rely on matching two lines at a time. There are other problems with your regexps, but that's the biggest. That can be solved by working with more than one line at a time.
my $file = do { local $/; <> }; 1 while $file =~ s/^([ ]{4}[^\n]+)\n[ ]{4}/$1/m; print($file);
Or better yet:
my $file = do { local $/; <> }; 1 while $file =~ s/^(([ ]+)(?![ ])[^\n]+)\n\2(?![ ])/$1/m; print($file);
Note: The second will unwrap all pragraphs, no matter how far they are indented.
Note: Both work with and without -i.
Note: 1 while s///; is used in order to repeatedly match the same line. s///g; won't work when the paragraph is more than two lines long.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: replace \n with space to join indented lines
by olivier (Initiate) on Dec 05, 2006 at 13:17 UTC | |
by ikegami (Patriarch) on Dec 05, 2006 at 16:10 UTC |