http://qs321.pair.com?node_id=870015


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.