I’m writing in Perl to direct my report in table format but I’m having issue whenever the data filling is texted too long. Is there a way a write the code so that it can wrapped the lines to m ultiple. Here is my code and output. Thanks!
printf "\n%-${max1}s %-${max2}s %-15s\n", "====", "====", "=====" ;
printf "%-${max1}s %-${max2}s %-15s\n", "Code", "Item", "Group" ;
printf "%-${max1}s %-${max2}s %-15s\n", "====", "====", "=====" ;
foreach my $f (@{$rpt_ptr}) {
printf "%-${max1}s %-${max2}s %-15s\n", "$$f{code}", "$$f{item}", "$$f{group}",
}
The output table will be extended to too long if I have the Item list which is too long, ie:-
==== ===== =====
Code Item Group
==== ===== =====
A1011 aaaaaa, bbbbb, ccccc, ddddd, eeeee, fffff, ggggg, hhhhh, iiiii, jjjjjj, kkkkk, llll B
B101 cccccc A
I’m aspected if I can comes out with a table such like:
==== ===== =====
Code Item Group
==== ===== =====
A1011 aaaaaa, bbbbb, ccccc, ddddd, B
eeeee, fffff, ggggg, hhhhh,
iiiii, jjjjjj, kkkkk, llll
B101 cccccc A
How am I going to achieve that?
Perl was originally written to format text files. It includes a rather interesting form generating facility, including the ability to wrap lines the way you’ve specified. I have not seen it used in a long, long while, but it’s still part of the language.
It’s in the Perldoc under perlform.
Example
Output