You should really truncate the log file example to only a couple of lines, as it is a bit annoying to scroll it all down.

Anyways, without looking at the rest of your code, here's an alternate shot at the iso2epoc sub. Not sure if that aproach is preferable, but it was the first idea that came to my mind (had to change the year to 2005 since timelocal doesn't seem to handle 2099 on my box).
use strict; use warnings; use POSIX qw(strftime); use Time::Local; sub iso2epoc { my $iso = shift; # check input and separate the date and time return undef unless ($iso =~ /^\@(?:(\d{0,8})T?(\d{0,6}))?$/); unless (length($iso) == 16) { my $date = $1 || ''; my $time = $2 || ''; # we need to know how many characters each has my $len_date = length($date); my $len_time = length($time); # get current date & time as defaults my $defdate = strftime("%Y%m%d", localtime); my $deftime = strftime("%H%M%S", localtime); # now we just copy the missing parts before the incomplete dat +e & time $iso = '@' . substr($defdate, 0, 8 - $len_date) . $date # this assumes T22 means 22:00:00 . 'T' . $time . substr($deftime, 0, 6 - $len_time) +; } if ($iso =~ /^\@(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})$/) { return timelocal($6,$5,$4,$3,$2 - 1,$1); } return undef; } foreach my $iso (<DATA>) { chomp $iso; my $epoc = iso2epoc($iso) or die "wrong input: $iso"; print "$iso -> $epoc (" . strftime("%Y-%m-%d %X", localtime($epoc) +) . ")\n"; } __DATA__ @20050122T000000 @050122T000000 @0122T000000 @22T000000 @T000000 @T0000 @T00 @22T @
prints:
@20050122T000000 -> 1106348400 (2005-01-22 00:00:00) @050122T000000 -> 1106348400 (2005-01-22 00:00:00) @0122T000000 -> 1106348400 (2005-01-22 00:00:00) @22T000000 -> 1114120800 (2005-04-22 00:00:00) @T000000 -> 1112392800 (2005-04-02 00:00:00) @T0000 -> 1112410800 (2005-04-02 05:00:00) @T00 -> 1112412540 (2005-04-02 05:29:00) @22T -> 1114140596 (2005-04-22 05:29:56) @ -> 1112412596 (2005-04-02 05:29:56)

In reply to Re^2: Postfix maillog parser by Golo
in thread Postfix maillog parser by nikos

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.