in reply to fixing paragraphs

You have to remove all white space from the beginning and end of each line. Then if a line break follows a character that is not an end of line (.?!), it is replaced with a space.

EDIT: Oops, forgot the g flag,and also forget to mask out \n itself. Fixed the problem.

EDIT: Oops again. I really must have been tired when I wrote this! As jwest points out via PM, I was only removing white space from the beginning OR end of the lines, not both at the same time. Fixed the problem.

use strict; use warnings; @_ = <DATA>; s/^\s+|\s+$//g for @_; $_ = join "\n", @_; ##### END OF LINE MARKERS s/([^\.\?!\n])\n+/$1 /g; ##### ADD TO AS NECESSARY print; __DATA__ This line breaks in the middle. This one doesn't. Neither does this! Or this? I hope.

Replies are listed 'Best First'.
Re^2: fixing paragraphs
by bfdi533 (Friar) on Jun 19, 2005 at 19:45 UTC
    This actually works great. But, I should have been more clear in my original post the output format that I needed. I am editing it now to add the final output that I am looking for. As I do not understand the code you provided except to say that it works, I do not know how to alter it to do what I want.