Use Time::Piece along with Time::Seconds to work with the time stamp. It's a lot cleaner and easier to work with than raw parsing. Plus, it makes doing your output a bit more flexible.
I could never get the flip/flop operator to do what I want. Just use an if
statement with the time range.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use autodie;
use Time::Seconds;
use Time::Piece;
use constant {
START_TIME => "2014/04/24-23:25:29",
TIME_PERIOD => 5,
TIME_FORMAT => "%Y/%m/%d-%H:%M:%S",
};
my $start_time = Time::Piece->strptime( START_TIME, TIME_FORMAT );
my $end_time = $start_time + ( ONE_MINUTE * TIME_PERIOD );
while ( my $line = <DATA> ) {
chomp $line;
my $time_string = $line;
$time_string =~ s/\..*//;
my $time = Time::Piece->strptime( $time_string, TIME_FORMAT );
if ( $time->epoch >= $start_time->epoch
and $time->epoch <= $end_time->epoch ) {
say "$line";
}
}
__DATA__
2014/04/24-23:29:20.003078-<String>
2014/04/24-23:29:32.003157-<String>
2014/04/24-23:29:33.004872-<String>
2014/04/24-23:29:43.005785-<String>
2014/04/24-23:30:43.005785-<String>
2014/04/24-23:31:43.005785-<String>