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

This question is grounded in the belief that 90% of every perl application has already been written.

Use case #1) I maintain some code which is deployed for multiple clients and reads configuration data based on the url used to access the application. One of its many functions is to send out emails for folks based on what happens on the online forms. Those emails interpolate configuration variables and the paragraphs in the email come out looking ragged and ugly, depending on what client its for and how long a string pulled from the configuration file might be injected into the template text.

Use case #2) I've got a project demanding to be completed which will generate letters (using PDF::API2) on client provided letterhead, ready for printing and mailing. These letters will essentially merge browser supplied data from our web forms with a form letter crafted (and updated from time to time) by my clients, to produce the final personalized letter, ready for printing, signature and mailing.

For both of these purposes I am seeking a module which will make my paragraphs look justified in much the same way which this mapping from my .vimrc file makes my email look good:

}jp J {!}fmt -65
Surely I am not the first person to have this need. All leads are appreciated.

-- Hugh Esco

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Seeking module for formatting text for output
by rhesa (Vicar) on Jan 11, 2008 at 00:11 UTC
Re: Seeking module for formatting text for output
by shmem (Chancellor) on Jan 11, 2008 at 00:28 UTC
    See perlform and Text::Template for use case #1.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Seeking module for formatting text for output
by perrin (Chancellor) on Jan 11, 2008 at 01:00 UTC
Re: Seeking module for formatting text for output
by aquarium (Curate) on Jan 11, 2008 at 02:26 UTC
    a lot will be decided by the details that you have not shown/investigated so far....the devil is in the detail, so to speak. For example, if some (or even one) of your clients still uses some shabby old PC with low res screen and an old version of Adobe Reader, then they won't get to read the newsletter unless created with backwards PDF compatibility is taken care of. Some email clients may try to display email/PDF attachment with their own inline reader egnine, and it may not render well or at all, depending on how well the PDF is crafted. Maybe some of your clients want to read the newsletter email on their usual choice for email reading, such as a Blackburry or such. Design for your audience making as few assumptions as possible OR you run the risk of having a beaut program that they don't/can't use for whatever reason.
    good luck.
    the hardest line to type correctly is: stty erase ^H
Re: Seeking module for formatting text for output
by stvn (Monsignor) on Jan 11, 2008 at 05:30 UTC

    I had a very similar problem once as well, although I also needed GIF outputs too. I wrote Text::Flow to solve it because I could find no text formatting/wrapping modules on CPAN which were not specific to monotype (fixed-width) fonts. I suspect it might be useful for you as well, feel free to /msg me if you have any questions.

    -stvn