So long as you can absolutely guarantee that commas will NOT appear any of the fields, you can quickly parse the line from the log file into a list with 'split'. Define some constants at the top of your file to represent their positions:
sub SERVER_NAME() { 0 } sub DATE() { 1 } # ... sub ERROR_TYPE() { 4 } # etc. while( <msg> ) { chomp ; @elements = split /,/ ; if( $elements[ERROR_TYPE] eq 'ERROR' ) { # handle error next ; } }
As for matching up uptimes and downtimes, that's a little trickier. You need to maintain some state information between each invocation of the script or the script needs to be constantly watching this file. The 'Storable' module will let you store a hash structure in a file and then retrieve it. This psuedo code may give you some guidelines where to start. It does not account for such frustrations as the log file disapearing and being recreated between runs.
use strict ; use Storable ; use FileHandle ; my($hashRef, $log) ; # program startup # read previous data: if( !-e 'myFile' ) { # myFile not found, assume we're starting from the beginning $hashRef->{lastPosition} = 0 ; # start at the beg # add other values as needed } else { $hashRef = retrieve('myFile') ; } $log = new FileHandle('logfile') ; $log->seek($hashRef->{lastPosition}, 0) ; # go back to previous point +searched ############# ## Process ## ############# ## ## save where the end of the file currently is, so ## we don't have to scan the whole file again next time ## $hashRef->{lastPosition} = $log->tell() ; # get file offset ## ## Store new state data ## store $hashRef, 'myFile' ;

In reply to Re: comma delimited, syslog parsing by ptkdb
in thread comma delimited, syslog parsing by jeff061

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.