http://qs321.pair.com?node_id=1035631

ericf706 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have made a socket that connects to a remote server and listens for incoming data, it writes the data to a file. The data stream is continuous, any breaks in the stream are not based an any pattern. The code works mostly, except that a new file is never created. I would like a new file to be created every 15 minutes. I realize this is because an EOF is never reached from the socket, and the socket is blocking the code from moving forward. I am not sure making the socket non-blocking will get me what I want, as there will almost always be data in the buffer to be read. Is there a way to get the desired behavior? I was considering either trying to use Fork in some way, or making a seperate script to handle to file seperation with the current script writing to generic file. Thanks, Eric

while($continue){ if ($socket->connected){ $quarter = $minute - ($minute % 15); ## if quarter != quarter 15 minutes has passed, create + new filename with the next 0 15 30 45 designation if($cur_quarter != $quarter){ ## close current file and move it to directory + for further processing close $fout; move("$dir.$filename","/home/ed/falbee/chrysle +r_asn/lu62asns"); $cur_quarter = $quarter; ## pad cur_quarter with 0 (make sure has two d +igits) $cur_quarter .= '0' x (2 - length($cur_quarter +)); $filename ="$date$cur_quarter"; open ($fout, ">>", $filename); } local $/ = '^\'; my $line = <$socket>; print $fout $line; }