kramer has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
First of all I would like to thank all for you for your efforts and time.
I have formed a hash and I am trying to for a table from the hash
contents.
which i am able to do, but I am not able to align the text inthe columns
to center. They are aligned to left which is the default.My code
$analysis_table = Text::Table->new(\'| ',"VIEW_NAME",\' | ',"UNCERTAIN +ITY_TYPE\n TNS | WNS ",\' | '); foreach my $key(keys %analysis_hash){ my $temp = "$analysis_hash{$key}->{'uncertainity_type'} | $ana +lysis_hash{$key}->{'uncertainity_type'}" ; $analysis_table->add($key,$temp) ; } my $rule = $analysis_table->rule(qw/- +/) ; my @body = $analysis_table->body; print $rule, $analysis_table->title, $rule; for (@body) { # align('center',$_); print $_ . $rule ; }
My Output
+-----------+-------------------+
|VIEW_NAME |UNCERTAINITY_TYPE |
+-----------+-------------------+
|view1 |0.1 | 0.2 |
+-----------+-------------------+
|view2 |0.3 | 0.4 |
+-----------+-------------------+
Desired output
+-----------+-------------------+
| VIEW_NAME | UNCERTAINITY_TYPE |
+-----------+-------------------+
| view1 | 0.1 | 0.2 |
+-----------+-------------------+
| view2 | 0.3 | 0.4 |
+-----------+-------------------+
every thing aligned to center. I tried using Text::Aligner but to no success.
Please help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: alignment of text in Text::Table
by Cristoforo (Curate) on Aug 19, 2012 at 17:13 UTC | |
by kramer (Initiate) on Aug 20, 2012 at 03:49 UTC | |
|
Re: alignment of text in Text::Table
by 2teez (Vicar) on Aug 19, 2012 at 11:29 UTC |