perltexttable

Text::Table rule repeating column separator at each intersection


I'm trying make a simple Perl text table using Text::Table. I want pipes as the main column separator, hyphens for a horizontal rule, and plus signs where the rule crosses the column separator.

Here is a MWE:

use strict;
use warnings;
use Text::Table;

my $sep = \'│';
my $tb = Text::Table->new("Heading 1", $sep, "Heading 2", $sep, "Heading 3");

$tb->add("Row 1 Col 1", "Row 1 Col 2", "Row 1 Col 3");
$tb->add("Row 2 Col 1", "Row 2 Col 2", "Row 2 Col 3");

print $tb->title;
print $tb->rule('-','+');
print $tb->body;

I used the suggestion from the Text::Table documentation that "Another useful combo is $tb->rule( '-', '+'), together with separators that contain a single nonblank "|", for a popular representation of line crossings."

But it's giving me this output:

Heading 1  │Heading 2  │Heading 3
-----------+++-----------+++-----------
Row 1 Col 1│Row 1 Col 2│Row 1 Col 3
Row 2 Col 1│Row 2 Col 2│Row 2 Col 3

Notice there are three plus signs at each rule/column intersection rather than the expected one.

I've tested this in Text::Table 1.133 and 1.135 (latest).

What am I doing wrong?


Solution

  • When I copied your code and ran it, I got a strange character instead of the pipe (|) in the output. Also, I do not see 3 plus signs like you do; I only see 1.

    I am using Text::Table version 1.135.

    When I change the $sep variable to:

    my $sep = \'|';
    

    I see this output:

    Heading 1  |Heading 2  |Heading 3  
    -----------+-----------+-----------
    Row 1 Col 1|Row 1 Col 2|Row 1 Col 3
    Row 2 Col 1|Row 2 Col 2|Row 2 Col 3
    

    See also: How can I print a table with multi-line strings using the Text::Table module?