Others have suggested various methods for parsing your logfile, to which I would add a suggestion to try looking at substr, especially if you're not yet totally comfortable with regular expressions and the uses thereof (and assuming that your records are fixed-width).

You don't say if you're planning to generate this table dynamically or to store it: if you're doing it on the fly, then I hope you're using CGI.pm, and if you are I suggest outputting the table the easy way, using the Tr and td functions.

If you have a row of data in an array variable (say, @foo), you can generate table cells for that row with the statement

my $html = td (\@foo);
and the Tr function can be used similarly.

So the relevant section of your code could look something like this highly off-the-cuff and untested fragment:

my @rows; while (<LOGFILE>) { my @data; #your routine of choice to split the input into fields #and stash it in @data push @rows, td(\@data); } print table (Tr (\@rows));

Which, as you see, makes the whole formatting question pretty much go away.

If you're not doing this dynamically, you could still use the CGI module (use CGI qw (:all -nodebug), but there are probably simpler solutions available on CPAN (try looking under the WWW section for HTML building solutions).



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders


In reply to Re: How to parse a logfile to a HTML table format by ChemBoy
in thread How to parse a logfile to a HTML table format by Suwen

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.