I've got text some text with line breaks. I want to strip all line breaks, unless there are two next to each other.
Here is what I have:
Code:
$text = "This is not good,\n you know what I mean?\n\nThis should be o
+n a separate line.";
$text =~ s/[^\n]\n[^\n]//g;
print $text;
Run:
C:\Perl>perl test.pl
This is not goodyou know what I mean?
This should be on a separate line.
Should Print:
This is not good, you know what I mean?
This should be on a separate line.
The (^\n) 's (brackets linked it, so I used parentheses there) are being substituted out, too, which is not wanted. How would I get around this?
Thanks,
madhatter
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|