Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Skip 2 new lines

by ww (Archbishop)
on Nov 08, 2010 at 04:23 UTC ( #870015=note: print w/replies, xml ) Need Help??

in reply to Skip 2 new lines

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://870015]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-01-23 08:35 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.