need a newline between paragraphs....

Chad Perrin perrin at
Wed Nov 25 20:36:44 UTC 2009

On Tue, Nov 24, 2009 at 01:19:42PM -0800, Gary Kline wrote:
> On Tue, Nov 24, 2009 at 01:07:41PM -0700, Chad Perrin wrote:
> 	precisely.  in this case, every paragraph that is not on a
> 	newline wraps.  so anything that has an EOL is a new
> 	paragraph.

If I understand you correctly, the following should work for your
purposes (as a naive implementation of the concept):

    my $contents;

      undef $/;
      open(my $fh, '<', $in_filename) or die $!;
      $contents = <$fh>;

    $contents =~ s/\n+/\n\n/g;

      open(my $fh, '>', $out_filename) or die $!;
      print($fh $contents);

That assumes that you want to turn any and all instances of one or more
consecutive newlines into exacty two newlines.  More finagling might be
required if there may be other adjacent whitespace, which would need to
account for not only possible adjacent whitespace but also possible
whitespace at the beginning of a line with other text on it.  Maybe
something like this:

    $contents =~ s/\s*\n+/\n\n/g;

. . . though I haven't thought it through in too much depth with regards
to the implications in edge case circumstances (thus the "naive
implementation" comment above).

> 	there are a few places that require different formatting; 
> 	these are easily re-done thanks to OOo!

I'm the kind of guy who would look for a way to automate things so that
re-formatting in OOo wouldn't be necessary, but as long as you're happy,
I guess we win.  Good luck!

Chad Perrin [ original content licensed OWL: ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url :

More information about the freebsd-questions mailing list