http://www.perlmonks.org?node_id=1013258


in reply to Close a file and reopen a new one at midnight

It looks like you are running a UNIX-like system. You may want to install a signal handler to reopen the filehandle and either alarm at midnight (and catch the ALRM signal) or send some signal (USR1, for example) via cron daemon and handle it. You can even automatically compress and/or remove old files using logrotate if you want.
Sorry if my advice was wrong.
  • Comment on Re: Close a file and reopen a new one at midnight

Replies are listed 'Best First'.
Re: Close a file and reopen a new one at midnight
by 0day (Sexton) on Jan 14, 2013 at 19:18 UTC
    my $timeout = 24*60*60 - ($hour*3600 + $min*60 + $sec); while(1) { eval { local $SIG{ALRM} = sub { die; }; alarm($timeout); while (my $line = <$sock>) { ................. } alarm(0); }; $timeout = 24*60*60; }