Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How to calculate earliest date from log file

by mbethke (Hermit)
on Nov 11, 2012 at 04:27 UTC ( #1003298=note: print w/ replies, xml ) Need Help??


in reply to How to calculate earliest date from log file

The easiest if not fastest way would be Date::Parse:

$ perl -MDate::Parse -E'say scalar gmtime str2time("08/Oct/2007:04:54: +20 -0400");' Mon Oct 8 08:54:20 2007

str2time() gives you the seconds since the epoch that you can easily compare.

Because Date::Parse has to do its format guessing every time you call the parsing function, you'd be much faster using a hand-crafted regexp with a little hash like

%months = ( Jan => '01', Feb => '02', ... ); s!(..)/(...)/(....):(..):(..):(..)!$3.$months{$2}.$1.$4.$5.$6!e;
or something along these lines, maybe correcting for the time zone if these should be allowed differ too in your log lines. However, if you're doing anything significant with your data afterwards, the speedup may not even be noticeable. A program I wrote in 2008 uses Date::Parse and parses millions and millions of lines a day---it was just never worth fixing and testing the fix for such a little speed gain.


Comment on Re: How to calculate earliest date from log file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003298]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-09-23 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls