Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-01-23 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?