in reply to parsing

Go back to the script that generates the log in the first place and store the epoch instead of the data you have. (or in addition to this stuff if you like to read it)
Then you can just subtract one epoch from the other to get total number of seconds. (The epoch is returned from time() )

So, for example, if your log now reads:

964644652 Wed Jul 26 13:50:52 2000 964644691 Wed Jul 26 13:51:31 2000
You can parse this like so:
use strict; # Always. my $logname = "log.txt"; open LOG, $logname or die "Failed to open $logname, $!"; my( $start, $stop ); while( $start = <LOG> ) { ($start) = split /\s/, $start; $stop = <LOG> or die "No End Time in LOG!\n"; ($stop) = split /\s/, $stop; my $time_in_seconds = $stop - $start; # Do something with $time_in_seconds print "$time_in_seconds\n"; } close LOG or die "Failed to close $logname, $!";
To get the log format I gave you I used:
use strict; my $t = time(); print $t, "\t", scalar localtime($t)";

Update: Tye Pointed out that split will take care of the remainder for me, so I took that out.

Also, you might want to note in the log which lines are 'start' and which are 'stop' so that you can catch errors (like failing to record the 'stop' time). Right now, you would only notice such an error if there is an odd number of occurances. (And only at the end of the script when it can't find an end time for the last entry.) Of course, then you would need to parse that extra bit of info from the log. But entries like:

START 964644691 Wed Jul 26 13:51:31 2000 STOP 964644691 Wed Jul 26 13:51:31 2000
should not be hard to parse. just call split /\s/ as before, and make the recieving array ($tag, $epoch) or whatever.

Replies are listed 'Best First'.
RE: (Adam: Use a better log format) RE: parsing
by toadi (Chaplain) on Jul 27, 2000 at 11:50 UTC
    Actually I'm working in linux and I use the ip-up and ip-down script to write the start and stop time to this log.
    --
    My opinions may have changed,
    but not the fact that I am right