So, for example, if your log now reads:
You can parse this like so:964644652 Wed Jul 26 13:50:52 2000 964644691 Wed Jul 26 13:51:31 2000
To get the log format I gave you I used: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, $!";
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:
should not be hard to parse. just call split /\s/ as before, and make the recieving array ($tag, $epoch) or whatever.START 964644691 Wed Jul 26 13:51:31 2000 STOP 964644691 Wed Jul 26 13:51:31 2000
In reply to (Adam: Use a better log format) RE: parsing
by Adam
in thread parsing
by toadi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |