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

Ok. I've got a large bit of text that I've wrapped with Text::Wrap. I now want to justify the text so that it looks like blocks of text you'd find in a manpage:

- all lines same length
- words spread evenly across all lines

I don't think this can be done with a format. Any ideas?

Replies are listed 'Best First'.
RE: Justify Text - Like a man Page...
by ColtsFoot (Chaplain) on Aug 30, 2000 at 16:10 UTC
    Have a look at Text::Format at CPAN. The following is straight from the documentation
    $text = Text::Format->new ( { text => [], # all columns => 72, # format, paragraphs, center leftMargin => 0, # format, paragraphs, center rightMargin => 0, # format, paragraphs, center firstIndent => 4, # format, paragraphs bodyIndent => 0, # format, paragraphs rightFill => 0, # format, paragraphs rightAlign => 0, # format, paragraphs justify => 0, # format, paragraphs extraSpace => 0, # format, paragraphs abbrevs => {}, # format, paragraphs hangingIndent => 0, # format, paragraphs hangingText => [], # format, paragraphs noBreak => 0, # format, paragraphs noBreakRegex => {}, # format, paragraphs tabstop => 8, # expand, unexpand, center } ); # these are the default values
    Justify is the attribute that you need to look at
    justify 0 || 1 || NOTHING
    Set justify or retrieve its value. Text is aligned with both margins,
    adding extra spaces as necessary to align text with left and right margins. Keep in mind that if either of rightAlign or rightFill are set then justify is ignored, even if both are set in which case they are all ignored.
    Hope this helps