in reply to dynamic filehandlers - how to deal?

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: }

Replies are listed 'Best First'.
Re^2: dynamic filehandlers - how to deal?
by ThirtySecondNoob (Novice) on Oct 08, 2010 at 17:12 UTC

    Thanks to both of you guys - you really know your stuff! Jethro, you nailed it right on the money there, and roboticus, that was a good assumption not to be limited to the number of files being open at a time, although in this case the data comes in as real time. Both of these are great to work with and have tricks that I would do well to remember.

    Thanks again!