It seems I don't have it and it is a big deal to get something we don't already have.

Unless it is a big deal to install the .pl you are writting, you should have no problem also installing Text::Table. Given that Text::Table is a pure Perl module with only pure Perl dependancies, there's no difference between installing your script and installing Text::Table.

But I wrote up an alternative anyway

use strict; use warnings; use List::Util qw( max ); sub get_max_widths { my ($titles, $aoa) = @_; my @col_widths; foreach my $row ($titles, @$aoa) { foreach my $col_num (0..$#$row) { $col_widths[$col_num] = max( $col_widths[$col_num] || 0, length($row->[$col_num]) ); } } return \@col_widths; } sub get_formatter { my ($col_widths, $justs) = @_; if (@$col_widths > @$justs) { $justs = [ @$justs, 'L' x (@$col_widths - @$justs), ]; } my $fstr = join ' ', map { '%' . ($justs->[$_] eq 'L' ? '-' : '') . $col_widths->[$_] . 's' } 0..$#$col_widths; my $args = join ', ', map { ($justs->[$_] eq 'C' ? "center(\$_[$_], $col_widths->[$_])" : "\$_[$_]" ) } 0..$#$col_widths; return eval "sub { sprintf('$fstr', $args) }"; } sub center { my ($text, $size) = @_; $size -= length($text); return $text if $size <= 0; my $s_half = int($size / 2); my $b_half = int(($size+1) / 2); return (' ' x $s_half) . $text . (' ' x $b_half); } { my @titles = ( 'TITLE', 'DATA-A', 'DATA-B', 'DATA-C', ); # (L)eft, (R)ight or (C)enter my @title_justs = ('C') x @titles; my @justs = ('L') x @titles; my @data = ( [ 'How are you', 'item1', 'item2', 'item3' ], [ '', 'item1a', 'item2b', 'item3c' ], [ 'I am fine', 'item4', 'item5', 'item6' ], ); my $col_widths = get_max_widths(\@titles, \@data); my $title_formatter = get_formatter($col_widths, \@title_justs); my $row_formatter = get_formatter($col_widths, \@justs); print $title_formatter->(@titles), "\n"; print $row_formatter->(@$_), "\n" foreach @data; }

In reply to Re: THANKS for the help...formatting followup by ikegami
in thread THANKS for the help...formatting followup by perlNinny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.