Mathew Snyder wrote:
> 
> Question regarding the text formatting modules out there.  I've found three on
> CPAN that seem to have the functionality that I'm looking for but I don't know
> which would best suit my needs.  The three are Text::Format, Text::Wrapper and
> Text::Autoformat.
> 
> I have a script which populates and email with data that gets laid out in the
> following manner:
> 
> customer_name
>  Ticket ID                      Subject                     hh:mm
> -----------------------------------------------------------------
>     ######  Random Ticket Subject Line                      ##:##
> 
> However, the subject length is not a constant.  It can be quite short (maybe a
> few characters long) to much longer than the alloted space I've given using
> 'printf'.  So, I'd like to be able to do things like wrap the text at a 
> certain
> length so that it might look something like this:
> 
> customer_name
>  Ticket ID                      Subject                     hh:mm
> -----------------------------------------------------------------
>     ######  Random Ticket Subject Line Which Might End Up   ##:##
>             Longer Than The Allocated Space Using printf
>     ######  Next Random Ticket Subject Line                 ##:##
> 
> Of the three formatting options I've found, which might be my best bet to 
> handle
> something of this nature.  Also, after deciding which is the better option, 
> how
> would I go about printing the data out?  Can I populate variables with
> pre-formatted text or would I perhaps do something with a printf command that
> uses a call to one of the formatting methods?
> 
> Any help would be appreciated.

$ perl -e'
my $customer_name = "customer_name";
my @records = (
    [ 1234, "Random Ticket Subject Line Which Might End Up Longer Than The
Allocated Space Using printf", "12:50" ],
    [ 1235, "Next Random Ticket Subject Line", "12:53" ],
    );


my ( $ticket, $subject, $time );

format STDOUT_TOP =
@<<<<<<<<<<<<<<
$customer_name
 Ticket ID                      Subject                     hh:mm
-----------------------------------------------------------------
.
format STDOUT =
    @#####  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   @>>>>
    $ticket, $subject, $time
~~          ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $subject
.

for my $record ( @records ) {
    ( $ticket, $subject, $time ) = @$record;
    write;
    }
'
customer_name
 Ticket ID                      Subject                     hh:mm
-----------------------------------------------------------------
      1234  Random Ticket Subject Line Which Might End Up   12:50
            Longer Than The Allocated Space Using printf
      1235  Next Random Ticket Subject Line                 12:53




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to