in reply to forgoing explicit file close
Agree .. agree .. agree .. upvote .. upvote .. upvote.
The entire process of handling a file is fraught with potential errors: opening it, read/write, seek, and close.. Your code therefore needs to explicitly do all of it, and to explicitly check for errors. You might have “successfully written” a bunch of data to the file, not realizing that it’s still in Perl’s buffers, when the file has gone away and the problem will not be detected until Perl attempts to write those buffers (e.g. at close time). Even if a warning message is produced, that is not something that your program can intercept and react to ... so, that’s not good enough. Your program will behave “mysteriously,” and that’s what causes the pager to go-off in the middle of the night or when you are having ... well, anyway ... ;-)Never let Perl do such things “by default.” Code like that only works when it works.