G'day hexcoder,

Here's a generic solution to your issue.

#!/usr/bin/env perl use strict; use warnings; my $multi_data_1 = [qw{ 123 456 789 0 _-=+ qwe rty uio p {[]} asd fgh jkl :; '" zxc vbn m <>?/ }]; print_table(MULTI_COL => 'QWERTY Keyboard', $multi_data_1, 5); my $step_data = [qw{Step2 0 4 Step3 4 4}]; print_table(STEP => 'TAB', $step_data, 3); my $multi_data_2 = [ 'skip1', '', 'skip2', '', '', 'skip2', '', '', 'skip1', '', 'skip', 'rest', ]; print_table(MULTI_COL => 'Skipped Cells', $multi_data_2, 5); sub print_table { my ($form, $title, $all_data, $cols) = @_; format STEP = .===================. |@<<<<<<<<<<<<<<<<< | $title .=======.===========. |@<<<<<<| @<</@>> |~~ get_col_data($all_data, $cols) .=======.===========. . format MULTI_COL = /=======================================\ | @|||||||||||||||||||||||||||||||||||| | $title |---------------------------------------| | @<<<< | @<<<< | @<<<< | @<<<< | @<<<< |~~ get_col_data($all_data, $cols) \=======================================/ . local $~ = $form; write; return; } sub get_col_data { my ($all_data, $cols) = @_; my @cols_data = splice @$all_data, 0, $cols; return @cols_data, ('') x ($cols - @cols_data); }

Output:

/=======================================\ | QWERTY Keyboard | |---------------------------------------| | 123 | 456 | 789 | 0 | _-=+ | | qwe | rty | uio | p | {[]} | | asd | fgh | jkl | :; | '" | | zxc | vbn | m | <>?/ | | \=======================================/ .===================. |TAB | .=======.===========. |Step2 | 0 / 4 | |Step3 | 4 / 4 | .=======.===========. /=======================================\ | Skipped Cells | |---------------------------------------| | skip1 | | skip2 | | | | skip2 | | | skip1 | | | skip | rest | | | | \=======================================/

Update: In get_col_data(), I changed three instances of @step_data to @cols_data. The output is unchanged. The original @step_data was from when I was initially testing with the OP's format (with Step2 & Step3). The change is in line with my opening statement that this was a "generic solution".

— Ken


In reply to Re: Avoid warnings while formatting with repeated format lines by kcott
in thread Avoid warnings while formatting with repeated format lines by hexcoder

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.