OK so lets break it down you want the data between a range of times. Your times in the logfiles are stored as strings which makes comparing them to a range difficult. Comparing numbers on the other hand is easy. So, here is how you convert between a string that represents your time and the unix epoch time which is the number of seconds between this time and 1 Jan 1970
use Time::Local; ($day,$mon,$year,$hours,$min,$sec) = split /[- :]/,"27-Jun-2001 12:08: +19.17"; print "$day,$mon,$year,$hours,$min,$sec\n"; $time = timelocal($sec,$min,$hours,$day,$mon,$year); print "$time\n"; print scalar localtime $time;
So now we can generate a number that represents our time, from the sort of data you can get from the logfile, the problem becomes much easier. You need to convert your time range to unix epoc seconds. You then read each line of the file, strip out the string that represents your time, and convert it to epoch seconds as well. If it is within the range of interest you are green to go, otherwise you go to the next line. Here is some code that does just this. I read from the DATA file handle to make it easy.
#!/usr/bin/perl -w use strict; use Time::Local; my ($day,$mon,$year,$hours,$min,$sec) = split /[- :]/,"27-Jun-2001 12: +08:19.50"; my $start = timelocal($sec,$min,$hours,$day,$mon,$year); # here is a shorter way using an array for our time elements my @time = split /[- :]/,"27-Jun-2001 12:08:21.50"; my $finish = timelocal(@time[5,4,3,0,1,2]); # iterate over our data while (<DATA>) { next if m/^\s*$/; # split the line into fields my @data = split /\s/, $_; # generate our time array my @time = split /[- :]/, "$data[0] $data[1]"; # convert to epoch time my $time = timelocal(@time[5,4,3,0,1,2]); # print the first three fields if in range if ($time > $start and $time < $finish) { print "$data[0] $data[1] $data[2]\n"; } } __DATA__ 27-Jun-2001 12:08:19.17 SendSMReq:T:1069 D:19203311338 O:Voice Mail M +WI P:0x20 C:0xe0 V:07-05 12:08 <20> 27-Jun-2001 12:08:19.36 SendSMCnf:AbsSub:1068 27-Jun-2001 12:08:19.56 SubmitInd:T:0 D:19207024720 O:19202928411 P:0 +x0 C:0x0 V:09-11 12:08 <yeah> 27-Jun-2001 12:08:20.05 SubmitInd:T:0 D:19207137406 O:19203314700 P:0 +x0 C:0x0 V:06-28 12:08 <LAST GF WAS 19 WAY TO IMMATURE, SUCKED IN BED +> 27-Jun-2001 12:08:20.30 SendSMReq:T:1070 D:16083089587 O:16083089560 +P:0x20 C:0x0 V:07-05 11:02 <good morning sleepy head> 27-Jun-2001 12:08:20.31 SubmitRsp:0 27-Jun-2001 12:08:20.32 SubmitRsp:0 27-Jun-2001 12:08:21.62 SendSMCnf:StatOK:1065 27-Jun-2001 12:08:22.36 SendSMCnf:StatOK:1060 27-Jun-2001 12:08:22.56 SendSMCnf:StatOK:1063
So all you need to do now is convert you input time range into unix epoch and you are set. As you have used a kludge I will not code this for you. If you just want to use the current day/month/year use the localtime() function to get what you need;
cheers
PS By the way did you know that a brass monkey was the thing that the old man o'war sailing ships used to store the cannon balls on. In the arctic the cold led to contraction of the brass and the cannon balls fell off. Thus was born the term "It's cold enough to freeze the balls of a brass monkey".
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: pattern match or key problem
by tachyon
in thread pattern match or key problem
by brassmon_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |