I'm trying to parse a logfile that has timestamped entries in it. The format is like this:

01/14/2014 23:44:12 <data1> <data2>

01/14/2014 23:44:12 <data1> <data2>

01/14/2014 23:44:13 <data1> <data2>

I'm splitting the line and using data2 as the key for a hash, and then pushing date, time, and data1 into an array that is the value, like this:

        push (@{$myHash{$data2}{info}}, "$date,$time,$data1");

However, my input file is not guaranteed to be sorted by time (in particular, some entries tend to be out of order by a second or two), and I need the output to be sorted. How can I sort those, either when I push entries into the array, or as I'm parsing it? I'm aware of Time::Piece, which I assume will help here, but I'm having trouble wrapping my head around the big picture of how to sort, especially in an efficient manner, as some of the input files are going to be pretty large.


In reply to sorting logfiles by timestamp by jasonl

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.