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

I'm currently using 5.6.1 and I had tested Damian Conway's Text::Autoformat. It seems like a good module. However it doesn't seem to do what it says it does. I'm wondering is it's the Perl version I'm using or if I'm doing something wrong.

Test code:
#!/usr/bin/perl use strict; use Text::Autoformat; undef $/; my $text = <>; print autoformat($text, {left=>20, right=>60});


Test text: (from the perldoc itself)


        In comp.lang.perl.misc you wrote:
        : > <CN = Clooless Noobie> writes:
        : > CN> PERL sux because:
        : > CN>    * It doesn't have a switch statement and you have to put $
        : > CN>signs in front of everything
        : > CN>    * There are too many OR operators: having |, || and 'or'
        : > CN>operators is confusing
        : > CN>    * VB rools, yeah!!!!!!!!!
        : > CN> So anyway, how can I stop reloads on a web page?
        : > CN> Email replies only, thanks - I don't read this newsgroup.
        : >
        : > Begone, sirrah! You are a pathetic, Bill-loving, microcephalic
        : > script-infant.
        : Sheesh, what's with this group - ask a question, get toasted! And how
        : *dare* you accuse me of Ianuphilia!


Yields:
                   In comp.lang.perl.misc you wrote:
        : > <CN = Clooless Noobie> writes:
        : > CN> PERL sux because:
        : > CN>    * It doesn't have a switch statement and you have to put $
        : > CN>signs in front of everything
        : > CN>    * There are too many OR operators: having |, || and 'or'
        : > CN>operators is confusing
        : > CN>    * VB rools, yeah!!!!!!!!!
        : > CN> So anyway, how can I stop reloads on a web page?
        : > CN> Email replies only, thanks - I don't read this newsgroup.
        : >
        : > Begone, sirrah! You are a pathetic, Bill-loving, microcephalic
        : > script-infant.
        : Sheesh, what's with this group - ask a question, get toasted! And how
        : *dare* you accuse me of Ianuphilia!

Supposed to yield:
        In comp.lang.perl.misc you wrote:
        : > <CN = Clooless Noobie> writes:
        : > CN> PERL sux because:
        : > CN>    * It doesn't have a switch statement and you
        : > CN>      have to put $ signs in front of everything
        : > CN>    * There are too many OR operators: having |, ||
        : > CN>      and 'or' operators is confusing
        : > CN>    * VB rools, yeah!!!!!!!!! So anyway, how can I
        : > CN>      stop reloads on a web page? Email replies
        : > CN>      only, thanks - I don't read this newsgroup.
        : >
        : > Begone, sirrah! You are a pathetic, Bill-loving,
        : > microcephalic script-infant.
        : Sheesh, what's with this group - ask a question, get toasted!
        : And how *dare* you accuse me of Ianuphilia!

Just wondering if anyone else will get the same result with 5.6.1 and a different result using an earlier version of Perl.

Thank you my brothers,

BMaximus

Edit: chipmunk 2001-06-22

Replies are listed 'Best First'.
Re: Text::Autoformat not behaving correctly
by bikeNomad (Priest) on Jun 22, 2001 at 07:33 UTC
    It formatted the first paragraph. To get the desired results (that is, to format all the paragraphs), just add "all=>1" to the options:
    #!/usr/bin/perl -w use strict; use Text::Autoformat; undef $/; my $text = <>; print autoformat($text, {left=>20, right=>60, all=>1});
      Thanks. Apparently the lack of a definition of what constitutes a paragraph to Text::Autoformat has gotten to me. You would think that according to the module's documentation that it would be able to discern what a paragraph is and what isn't. Its not really clear in the paragraph section.

      Quote:
      The fundamental task of the autoformat subroutine is to identify and rearrange independent paragraphs in a text. Paragraphs typically consist of a series of lines containing at least one non-whitespace character, followed by one or more lines containing only optional whitespace. This is a more liberal definition than many other formatters use: most require an empty line to terminate a paragraph. Paragraphs may also be denoted by bulleting, numbering, or quoting (see the following sections).

      Once a paragraph has been isolated, autoformat fills and re-wraps its lines according to the margins that are specified in its argument list. These are placed after the text to be formatted, in a hash reference:


      ++ to you BikeNomad

      BMaximus
        If you can get a copy of the latest Perl Journal (#20), Damian Conway's written an article about Text::Autoformat that discusses this. Quote: "autoformat understands all these notions of a paragraph. Even when they're all used at once. Even when they're used inside one another (for example, quoting a list of bulleted points)."

        -- Frag.