Abigail said:
Well, if someone else unlinks, overwrites or moves the file, the program
most likely doesn't do what you expect, regardless whether this happens
before, or after the chmod. And your program doesn't magically do what
you expect under such conditions if you use sysopen.
You're right, of course. It's just one of the things to
consider. Another is that in this case, the file is supposed to be
unreadable for anyone but the user writing it, but using
chmod($filename) after an open() leaves a short time window during which
someone else could possibly open the file for reading (or maybe even
read+write), which would give them access to the contents of the file as
long as they keep the handle.
Just saying, /if/ you need to specify restrictive permissions, you
probably want to do that it reliably as possible.