I am using CPAN Text :: Table module . I have a table in my script, and some values are multiline rows. I also use the rule to print this table.
My code is as follows:
use FindBin;
use lib "$FindBin::Bin/mylib/Text-Aligner-0.12/lib/";
use lib "$FindBin::Bin/mylib/Text-Table-1.130/lib/";
use Text::Table;
my $tb = Text::Table->new(\'| ', "", \' | ', "Field ", \'| ', "Length ", \'| ', "Comment ", \' |');
my @AoA = (
[ 1, "Foo", "20", "Foo" ],
[ 2, "Bar", "35", "Bar\nBar" ],
[ 3, "Tze", "10", "Tze\nTze" ],
);
$tb->load(@AoA);
my $rule = $tb->rule(qw/- /);
my @arr = $tb->body;
print $rule, $tb->title, $rule;
for (@arr) {
print $_ . $rule;
}
However, when I run this, I get the following:
|---|-------|--------|----------|
| | Field | Length | Comment |
|---|-------|--------|----------|
| 1 | Foo | 20 | Foo |
|---|-------|--------|----------|
| 2 | Bar | 35 | Bar |
|---|-------|--------|----------|
| | | | Bar |
|---|-------|--------|----------|
| 3 | Tze | 10 | Tze |
|---|-------|--------|----------|
| | | | Tze |
|---|-------|--------|----------|
Is there a way to not print single lines in case of multi-line lines?
I want to display the table as follows:
|---|-------|--------|----------|
| | Field | Length | Comment |
|---|-------|--------|----------|
| 1 | Foo | 20 | Foo |
|---|-------|--------|----------|
| 2 | Bar | 35 | Bar |
| | | | Bar |
|---|-------|--------|----------|
| 3 | Tze | 10 | Tze |
| | | | Tze |
|---|-------|--------|----------|