in reply to Splitting up a file in hourly increments

I'm going to take stab at what I think you are doing - correct me if I don't have it right.

It seems that you are monitoring a log file, and you want to split the data into hourly log files (and perhaps perform some processing on them, too.)

Assuming this is what you want to do, here's my approach:

my ($t0, $path0, $out); $t0 = time; $path0 = path_for_time($t0); open($out, ">>", $path0); # note below while (defined(my $line = readline())) { my $t = time; my $path1 = path_for_time($t); if ($path1 ne $path0) { close($out); $path0 = $path1; open($out, ">>", $path0); } print $out $line; flush($out); # note below ... perform other processing on $line ... }
All you need to supply is the path_for_time() subroutine.

The routine readline() can just read from a pipe from tail as it seems like you are doing or you can use File::Tail to move the functionality into the perl script itself. Also, I use open the output files in append mode and call flush() in case you ever make this script restartable someday.

Is this what you want to do?