Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I output a text table in Perl?

I want to output a table containing four variables, an example of the desired format is:

A confusion matrix

H        |    P     |
-----------------------
$var1    |   $var2  | H
$var3    |   $var4  | P

The problem I am having is that depending on the number of digits in the variables, the format changes and the various lines are offset. I know this is a complete noobie question, but I have never had to pay too much attention to the format of output before, its just one of those little things I want to get right this time. Any help at all would be great, thanks.

like image 854
B. Bowles Avatar asked Mar 29 '11 12:03

B. Bowles


People also ask

How do I print text in Perl?

print() operator – print operator in Perl is used to print the values of the expressions in a List passed to it as an argument. Print operator prints whatever is passed to it as an argument whether it be a string, a number, a variable or anything. Double-quotes(“”) is used as a delimiter to this operator.

How do I make a table in Perl?

#!/usr/bin/perl use strict; use Template; my $template=Template->new({PRE_CHOMP => 1}); my @rows; push @rows,["a","b","c","d","e"]; push @rows,["a","b","c","d","e"]; push @rows,["a","b","C","d","e"]; push @rows,["a","b","c","d","e"]; $template->process("table.

How do I format in Perl?

Defining a Format Syntax to define a Perl Format: format FormatName = fieldline value_1, value_2, value_3 fieldline value_1, value_2, value_3 . – Name of the format is denoted by the FormatName. – Fieldline is a particular way used to format the data.


1 Answers

Text::Table, Text::SimpleTable::AutoWidth

like image 162
daxim Avatar answered Oct 11 '22 00:10

daxim