sry guys and thnx for reponding ....I am very new to perl scripting and Here is my code
I can get $day, $time1,$time2,$time3,$time4 from command line arguements
$log="output.txt"
open(FILE,$log);
open(DATA,">>capdata.txt");
while(<FILE>)
{
if ($_ ge "$day $time1:time2" && "$day $time3:$time4")
{
print DATA;
}
}
I worte the script..but this is working for these kind of logs(log starting with timestamp
2006-04-06 09:22:00|Mike|USA
2006-04-06 09:23:99|Steve|Canada
2006-04-06 09:22:44|Bond|japan
| [reply] |
Sorry, my previous remark on .. and ... was silly. These operators won't help you here, since you don't know whether there actually is an entry in the log file with the very starting/ending times of the interval you are checking for.
In this case, I would proceed as follows:
Convert your string timestamp (2006-04-06 09:22:44) into a numeric value. You can do this forexample by extracting the respective fields by a regexp, and then use the functions in Time::Local to convert them into a time value. If you do the same with the starting/ending time, you can use numeric comparision to see whether the record falls within the range.
If you don't want to fiddle around with regular expressions (though in your case, they will be simple, because the timestamp always looks alike, doesn't it?), you could maybe use Date::Parse from CPAN. I have never worked with Date::Parse though, so I can't really say how useful it is for your application.
--
Ronald Fischer <ynnor@mm.st>
| [reply] |
small correction in if condition
if ($_ ge "$day $time1:time2" && $_ le "$day $time3:$time4")
| [reply] |
You can't compare dates like that (meaningfully, anyway). Go search the CPAN for a suitable date module that can
- understand your input data
- compare dates and time
- present dates and times in a format you prefer
Perhaps DateTime::Format::Strptime could be useful?
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
| [reply] |