Instead of thinking in terms of modifying (cargo-culted?) code, you'll probably do better thinking through exactly what has to happen, given the data you failed to include, initially (but have, in effect, provided in your first reply).

For example, assuming your description means data like this:

this is a line which is part of a sentence. And this is the second sentence in the target paragraph. This should be the start of a new paragraph ....

Then it's pretty obvious that you should remove any instance of \n that's not followed immediately by another... but leave any instance of \n\n alone.

And having performed that analysis, you can look for methods of implementing such an algorithm.

Hint: you'll find one answer in the discussion of regexen which "look ahead" in the documentation for regular expressions -- perldoc perlretut.

Another approach, since you say you're working from a file, would set $/ to match the double newline. You can read about that in any number of posts (easily found usings Super Search or in perlvar).

Update: Oops. brain-lock alert! I should have noted (above) that murugu's response is a valid suggestion... and also that AnonyMonk should not presume that pointers like that are completed code. Since AM posted no code to illustrate the statement "This didn't quite do what I was hoping..." it's hard to tell where the problem lies.

So, Anonymous Monk, please read On asking for help, How do I post a question effectively? and I know what I mean. Why don't you? for some more suggestions; suggestions about how to help us to help you.


In reply to Re: Skip 2 new lines by ww
in thread Skip 2 new lines by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.