Ok, i've decided to skip using the Date::Manip coz its giving me lots of
problems. Is there a way to compare dates (e.g. Thu Jun 20 12:00:00 2002)
and sort them in order? What i've always wanted is to sort them, and
subsequently using User's input of Start & End date to capture relevant logs
as explained below.

Assuming that $noforlines is the no of lines the log file has, and that
$convertedList[] contains the dates, while $user_start & $user_end
containing the user's desired start & end date, how do i compare dates? The
below coding doesn't seem to work right.

for ($s=0;$s<$noforlines;$s++) {
    if (($convertedList[$sian]>= $user_start)&&($convertedList[$sian]<=
$user_end)) {
 open (USER, ">>${filename}_REQUEST.TXT");
 print USER "$convertedList[$sian]\t$inputList[$sian]\n";
    }

Pls advise, thanks.

Regards,

~ HENRY WONG ~


----- Original Message -----
From: "david" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, September 28, 2002 5:31 AM
Subject: Re: Searching & Storing


> Henry Wong wrote:
>
> > Hi all,
> >
> > I am wondering if you guys can help me out here:
> > I have a log file containing information like this:
> >
> > THU DEC 6 14:55:00 2001    111    222    333    444
> > FRI DEC 7 01:00:00 2001   555    666    777    888
> > SAT DEC 8 13:00:00 2001    xxx    xxx    xxx    xxx
> > SUN DEC 9 04:00:00 2001    xxx    xxx    xxx    xxx
> > MON DEC 10 12:00:00 2001    xxx    xxx    xxx    xxx
> > TUE DEC 11 09:00:00 2001    xxx    xxx    xxx    xxx
> > :
> > :
> > :
> > & so on...
> >
> > Having the above log file with the first column containing the usual
TIME,
> > following by 4 columns of numerical data, I am thinking of having this
> > program asking the user to input his/her desired starting date & ending
> > date, and thus thereby extracting all the relevant 4 column datas
> > corresponding to the above dates.
> >
> > What i'm trying to say is, lets say the user inputs START DATE to be THU
> > DEC 6, and END DATE to be MON DEC 10. So my code will then extract all
> > relevant data corresponding to THU DEC 6 (which is 111, 222, 333, 444)
up
> > till MON DEC 10. That means the code would've extracted all 5 rows of
data
> > with their corresponding 4 xxx columns (from start date to end date),
and
> > then putting it into a file.
> >
> > Is this possible? How do I code the above concept? Do advise me, thanks
in
> > advance!
> >
>
> yes. with Date::Manip, it can be easily done:
>
> #!/usr/bin/perl -w
> use strict;
> use Date::Manip;
>
> my @db;
> open(LOG,'data.log') || die $!;
> while(<LOG>){
>         chomp;
>         my @fields = split(/\s+/);
>         my $date = ParseDate(join(' ',@fields[0..4]));
>         my $seconds =
Date_SecsSince1970(UnixDate($date,'%m'),UnixDate($date,'%d'),
>
UnixDate($date,'%Y'),UnixDate($date,'%H'),
>
UnixDate($date,'%M'),UnixDate($date,'%S'));
>         push(@db,[$seconds,@fields[5..$#fields]]);
> }
> close(LOG);
>
> while(1){
>
>         my @dates = (undef,undef);
>
>         for(1..2){
>
>                 print "Enter date: ";
>                 my $d = <STDIN>;
>
>                 exit if($d =~ /^exit/i);
>
>                 my $t = ParseDate($d);
>
>                 my $index = 0;
>                 $index = 1 if(defined $dates[0]);
>
>                 $dates[$index] =
Date_SecsSince1970(UnixDate($t,'%m'),UnixDate($t,'%d'),
>
UnixDate($t,'%Y'),UnixDate($t,'%H'),
>
UnixDate($t,'%M'),UnixDate($t,'%S'));
>         }
>
>         foreach my $i (@db){
>                 if($i->[0] >= $dates[0] && $i->[0] <= $dates[1]){
>                         print "Found: ",join(' ',@{$i}),"\n";
>                 }
>         }
> }
>
> __END__
>
> try it and see what happen. i am sure you can make it better.
>
> david
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

This e-mail is intended only for the named addressee(s) and may contain confidential 
and/or privileged information. If you are not the named addressee (or have received 
this e-mail in error), please notify the sender immediately and destroy this e-mail. 
The unauthorised use, disclosure, distribution or copying of the contents in this 
e-mail is strictly prohibited."
This e-mail is intended only for the named addressee(s) and may contain confidential 
and/or privileged information. If you are not the named addressee (or have received 
this e-mail in error), please notify the sender immediately and destroy this e-mail. 
The unauthorised use, disclosure, distribution or copying of the contents in this 
e-mail is strictly prohibited."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to