If I understand correctly, you're wondering what the best data structure for storing the parsed data would be, right? I'd say that depends on what you intend to do with it later on, but as a general rule of thumb, it's usually best to use what most closely resembles the natural structure of the raw data you're reading.

Going by your sample data, this would seem to be an array of hashes, indexed by the event number (0, 1, ...) and then the various fields appearing in these logs. Which is pretty much what you're doing, though you're using a hash with integer keys -- an array in all but name, really.

I want to analize this and report how many instances of errors there are per log type.

That said, I'm not sure what you mean here. What is a "log type"? Assuming you have a variable encoding this, if you merely want aggregates, you could do this in your loop:

... # calculate $logtype $hash_ref->{$logtype}++;

In other words, it all depends on what you want to do.

And bonus question: right now I discard the Description value because it appears on a different line after the ':'. Is there a way of getting this value as well. This is not very important because we have the event id and the logname, so we can deduce the value but it would be nice to have. Thanks!

You should be able to just read from DATA again, like so:

if($_ =~ /\s+Description.*$/) { chomp($description = <DATA>); }

In the event that the description can span several lines, add another loop there that keeps on reading from DATA until it encounters an empty line:

if($_ =~ /\s+Description.*$/) { while(chomp($description_line = <DATA>)) { last if $description_line eq ""; $description .= $description_line } }

Note that none of this is tested in any way.


In reply to Re: question on data structure by AppleFritter
in thread question on data structure by natxo

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.