http://www.perlmonks.org?node_id=586908


in reply to print log file

Perhaps you could use Tie::File so that you can access the log file as if it was an array. You could then quickly find the index in the array where the timestamp passes the threshhold by using a binary chop. Look half-way along the array, check the timestamp. If it is less than the threshhold, look again half-way along the upper half, else half-way along the lower half. Repeat, each time chopping the number of elements to be searched in half. Once you have found the element you can print from there to the end of the array.

Just a thought.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: print log file
by MidLifeXis (Monsignor) on Nov 30, 2006 at 18:18 UTC

    Also known as a binary search (term must have changed since I went to college).

    --MidLifeXis

      It must have been 25 years ago that I was told about this technique and the name given then was binary chop, I guess because you successively chop the range to be searched in half. Perhaps the name depends on which side of the Atlantic you live. Strangely enough, until today, when I coded one to test if my suggestion worked (it did), I had never had occaision to use one.

      Cheers,

      JohnGG