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

You have to use a global variable of an open file:
my $file; open $file, ">$filename" || die("Couldn't open file"); ...

In addition, are you assured that at this time there is data on the socket for reading?

Replies are listed 'Best First'.
Re^2: Close a file and reopen a new one at midnight
by MidLifeXis (Monsignor) on Jan 14, 2013 at 18:01 UTC

    That, however stylish it may be, using lexical file handles will not resolve the root cause of the problem. The file handle is being closed and reopened in a logically correct location.

    Update: Updated statement to clarify.

    --MidLifeXis