in reply to Parsing timestamps

Since the time information inside of your files seems to be in a good enough form that you could compare them directly with a string comparison, you could do something like this:

use POSIX qw/strftime/; # generate a timestamp of 12 hours ago in the same format as the data +file $twelve_hours_ago = strftime("%Y-%m-%d/%H:%M:%S",localtime(time-12*360 +0)); while (<FH>) { next unless /PASS/; # skip the non-PASS entries my ($date) = /^([^.]+)/; # grab the date up to seconds next unless $date gt $twelve_hours_ago; # process the interesting records. }
Update: I had a numeric comparator where clearly a string comparator is warranted and fixed the problem with the 12 hour ago timestamp. Thanks neilwatson, japhy

Update #2: While I'm thinking about it, note that this solution probably breaks at DST boundaries.

Replies are listed 'Best First'.
Re^2: Parsing timestamps
by neilwatson (Priest) on Nov 04, 2005 at 16:01 UTC
    use POSIX qw/strftime/; # generate a timestamp of 12 hours ago in the same format as the data +file $twelve_hours_ago = strftime("%Y-%m-%d/%H:%M:%S",localtime);
    Wouldn't that generate a timestamp of now?

    Neil Watson
    watson-wilson.ca

Re^2: Parsing timestamps
by japhy (Canon) on Nov 04, 2005 at 16:21 UTC
    Apart from the 12-hours-ago problem stated above me, you also need to use the string comparison operators (gt instead of >) here.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart