eznoh has asked for the wisdom of the Perl Monks concerning the following question:

I'm using text:wrap to break long lines into multiple lines, the problem is the long lines are terminated by two newline characters, wrap seems to be eating the second newline.

Replies are listed 'Best First'.
Re: Wrap eats newlines
by arden (Curate) on Jun 18, 2004 at 16:05 UTC
    eznoh, not to be mean, but RTFM! From the description of Text::Wrap, "It will destory any whitespace in the original text." That includes the extra newline character. Now, if you use  Text::Wrap::wrap() individually on each paragraph, you can then add the extra newline yourself.

    - - arden.

      I did RTFM, I guess I should have asked, is there an easy way to do what I want or a different function to use? Thanks!

        Since you know that Text::Wrap eats the whitespace, you can put the newline(s) back yourself.

Re: Wrap eats newlines
by davido (Cardinal) on Jun 18, 2004 at 16:09 UTC
    The POD for Text::Wrap says that all whitespace will be destroyed.

    Dave

Re: Wrap eats newlines
by PodMaster (Abbot) on Jun 19, 2004 at 12:14 UTC
    use Text::Wrap; use strict; use warnings; local $Text::Wrap::columns = 3; my $f = "blah blah blah\nblah blah\n\nblah blah halb halb halb\n\nhalb + halb halb"; for my $line( split /\n\n/, $f ){ print wrap('','',$line), "\n\n"; } __END__ bl ah bl ah bl ah bl ah bl ah bl ah bl ah ha lb ha lb ha lb ha lb ha lb ha lb

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.