Well, as the previous poster pointed out, you really didn't give much information to work with... so without knowing more about your data or application, here's some general stuff using what you did provide and guessing / assuming some stuff to illustrate an example. This little bit of code will reproduce the output in your original post:
#! /bin/perl ## what we'll name our columns -- note that there is no ## provision for having more data items than columns. They ## will simply get displayed formatted corretly but ## w/o column headings my @cols = qw/TITLE DATA-A DATA-B DATA-C/; ## if we assume your data is arranged like so: ## (which also assumes no title or data can contain ## a '#' char) my @data = ( 'TITLE#How are you#item1#item2#item3', 'item1a#item2b#item3c', 'TITLE#I am fine#item4#item5#item6', ); my $fixed_width = 16; # assume fixed-width for table cells ## If you wanted to you could use the substr() function to ## enforce the column width print join(' ', map{ sprintf("%-*s", $fixed_width, $_) } @cols), "\n" +; ## Then this is an easy way to pick it apart and display ## it as a table: foreach (@data) { my ($title, @data) = map{ /#/? split(/#/, $_) : $_ } (/^\s*(?:TITL +E#(.*?)#)?(.*?)$/g); print join(' ', map{ sprintf("%-*s", $fixed_width, $_) } ($title, + @data)), "\n"; }

In reply to Re: Looking for Perl Elegance! by bratwiz
in thread Looking for Perl Elegance! 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.