in reply to Design/Style question about writing to a file from different functions

In your first scenario solution 1 looks much better for the simple reason that you don't duplicate code (like opening the file 4 times). Duplicate code means more room for bugs if you ever have to change something

In your second scenario I would desperately look for a different solution. Changing a line in an already written file is always a hassle. If the contents of the file fits into memory, why not wait with writing to disk and juggle lines in an @array instead. Reordering lines in an array with splice is absolutely trivial

  • Comment on Re: Design/Style question about writing to a file from different functions