@lines = <LOGFILE>; foreach $line (@lines) { if ($line != m/\s/) { # regex to turn dates into epoch ($dd, $mm, $yy, $hh, $mt, $tt, $tdd, $tmm, $tyy, $thh, $tmt, $ttt) = $ +line =~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+)\s(am|pm)-(\d+)-(\d+)-(\d+)\s( +\d+):(\d+)\s(am|pm)/;
You say dd-mm... but then in the regex you have \d+. If you want to have just two digits, then something like this would work:
$line =~ /(\d\d)-(\d\d)\s+(\d\d):(\d\d)\s+([ap]m)-(\d\d)-(\d\d)-(\d\d) +\s+(\d\d):(\d\d)\s+[ap]m/

Notice I changes (am|pm) to [ap]m. Character class is faster than alternation, and since m is repeating in both you don't need to have that included in the alternative. Have you looked at the various Date:: modules?

if ($tt == 'pm') { $hh = $hh + 12; } if ($ttt == 'pm') { $thh = $thh + 12; }

Uh-ohh.... someone didn't have use strict/use warnings on ... did they?

if ($tt eq 'pm') { $hh += 12; } if ($ttt eq 'pm') { $thh += 12; }

You'll notice I used the perlop 'eq' here (== is numeric, we don't want numeric; use strict/use warnings issues a warning for this I believe). I also changed the $a = $a + $b form to $a += $b. Not necessary, but it looks a little better (to me :).


In reply to Re: Simple log parser by dimmesdale
in thread Simple log parser by Anonymous Monk

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.