You seem to want to write lines with the same time stamp to the same file, right? And when a line has a new date you need to close the old file and open the new one, right?
If that is the case, just remember the time of the previous line. If that is different than that of the new line, open a new file. And since opening with '>>' also creates a file you don't have to test for existence of the file.
my $previous_time=''; while (1) { #get line of code $new_line #get line's date stamp $line_time if ($line_time ne $previous_time) { close(CURRENT_FILE) if ($previous_time); #could be left out since +opening a new file closes the old open(CURRENT_FILE, ">>$DATA_DIRECTORY".$line_time.".ascii") or die "$line_time.ascii could not be created\n"; $previous_time= $line_time; } print CURRENT_FILE $new_line: }
In reply to Re: dynamic filehandlers - how to deal?
by jethro
in thread dynamic filehandlers - how to deal?
by ThirtySecondNoob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |