in reply to Replacing the pattern
First, change your substitution regexp to: s/$pattern/' ' x length( $1 )/gie; ...note the use of $1 instead of $&. It is advisable to always avoid $& if possible for performance reasons.
Now to answer your question: Use a second regexp to keep it simple, and it should look like this:
$target_data =~ s/(\n{2,})/'\n' . ( ' ' x length( $1 ) ) /ge;
That converts any blank lines to a line with spaces in it equalling the number of blank lines found in a row. If you don't want the blank spaces to occupy a new line, remove the '\n' part from the right side of the substitution regexp.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replacing the pattern
by agynr (Acolyte) on Jan 20, 2005 at 10:00 UTC | |
by Zaxo (Archbishop) on Jan 20, 2005 at 11:07 UTC | |
by agynr (Acolyte) on Jan 20, 2005 at 11:28 UTC | |
by agynr (Acolyte) on Jan 20, 2005 at 11:43 UTC |