vishi has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I have a really interesting situation here. I have a log file (basically a CSV) where each line is something that's got to do with a user's session. Each of these lines has a timestamp. A Sample is given below:
ABC01, 91XYZ889=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 02-Dec-2011_ +00.34.51, bigFatLog_02-Dec-2011_00.34.06.log ABC03, 93XYZ272=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 07-Dec-2011_ +09.21.58, bigFatLog_07-Dec-2011_09.20.57.log ABC02, 93XYZ807=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 08-Dec-2011_ +23.00.15, bigFatLog_08-Dec-2011_22.59.34.log ABC05, 91XYZ525=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 10-Dec-2011_ +10.01.36, bigFatLog_10-Dec-2011_10.01.00.log ABC01, 93XYZ252=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 12-Dec-2011_ +11.58.23, bigFatLog_12-Dec-2011_11.57.20.log ABC03, 93XYZ543=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 12-Dec-2011_ +23.34.07, bigFatLog_12-Dec-2011_23.33.23.log ABC04, 92XYZ066=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 13-Dec-2011_ +01.00.31, bigFatLog_13-Dec-2011_00.59.29.log ABC05, 93XYZ184=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 13-Dec-2011_ +01.54.41, bigFatLog_13-Dec-2011_01.54.04.log
Now, here's what am trying to do - My program accepts 2 dates as command line args, the first arg is the start date and the second one is the end date. Something like this :
perl getMyStats.pl 01-Dec-2011 11-Dec-2011
Now, I need to extract only those lines from the above CSV file which fall in this date range. I'm confused how to go about this one. I have thought of the following approach:
I need to know whether this is the right approach, or whether Perl has better tricks up its sleeve to make my job easier. I am familiar with Date::Calc, but I don't know how it will be useful here. If what I have thought of is correct, How do I go about "expanding" the date range, i.e., in my example, how do I convert 01-Dec-2011 11-Dec-2011 to a list with individual dates as its elements?
Suggestions please?!?!
|
|---|