I thought that by using the slurp mode, I could essentially edit the file in place without having to create a temporary file.
No, that is unsound. You can corrupt your log files.
Consider:
- Slurp the log file.
- Apply regex to file contents.
- Write the log file with new file contents.
Now, if the write fails due to "disk full" (a distinct possibility in your environment) or because you lose
power at that instant, or for any old reason, you have
just corrupted your log file.
Generally, you should write the modified file to a
temporary file and rename the temporary file over the original only after checking that the temporary file was created without error.