John W. Krahn wrote: > 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
Thanks for enlightening me about 'format' I've run your example code from the command line and got exactly the results you did (not that I'd expect to get anything different ;) ). I then attempted to incorporate the idea into my script: foreach my $user (keys %tikNums) { open TIMESHEET, ">/work_reports/ticketlists_$endDate/ticketlist_$user.txt"; print TIMESHEET "List of tickets worked on by $user during week ending $endDate", "\n\n"; foreach my $env (sort keys %{ $tikNums{$user} }){ #Print the header for our data print TIMESHEET $env . "\n"; printf TIMESHEET "%10s%10s\n", "Ticket ID","hh:mm"; print TIMESHEET ("-" x 20); print TIMESHEET "\n"; foreach my $id (sort keys %{ $tikNums{$user}{$env} }) { format STDOUT_TOP = @<<<<<<<<<<<<<<<<<<<< $env Ticket ID Subject hh:mm ------------------------------------------------------------------------- . format STDOUT = @###### ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>:>> $id, $tikSubj{$id}, $tikNums{$user}{$env}{$id} ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $tikSubj{$id} } write TIMESHEET; print TIMESHEET "\n"; } close TIMESHEET; } However, when I run the script I get the following error: Format not terminated at ./ticket_lists.pl line 128, at end of line syntax error at ./ticket_lists.pl line 128, at EOF Execution of ./ticket_lists.pl aborted due to compilation errors. Line 128 only contains my 'exit;' statement. I've got the periods where they belong but can't figure out why it would tell me the format hasn't been terminated. Any insight will be appreciated. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/