in reply to Opening multiple output files within a loop

What I would generally do in this case is to "start with a presumed-empty directory that has been specified by the user." Now, each time the chromosome changes, open the appropriate target file in append ">>" mode. Yes, it will be necessary for the user to be sure in-advance that the target directory is empty, but that should be fine. The program will now open each file (if it already exists) positioned at the end-of-file, or will create the file if it is new.
  • Comment on Re: Opening multiple output files within a loop

Replies are listed 'Best First'.
Re^2: Opening multiple output files within a loop
by Laurent_R (Canon) on Dec 19, 2017 at 23:36 UTC
    Hm, I am not sure to understand. Do you mean that you want to run an open statement in append mode for each line with a different chromosome in the input file? That would be very inefficient, as opening a file takes some time. You might want to dynamically open files only if you need to, but then you really want to open files only if they have not been opened before. From the OP, however, it seems that the program is receiving the list of chromosomes used in the file as an argument to the program.