http://qs1969.pair.com?node_id=350028


in reply to Re: if (open(FH, $path)) { ?
in thread if (open(FH, $path)) { ?

Note that this is a theoretical race problem. The code could potentially run the test and determine that the file is readable, writeable, whatever.

In the intervening period between the test and the moment you attempt to open the file, the permissions might have changed, or the file itself may no longer be around.

It's the classic resource acquisition problem. Sometimes, no amount of testing can tell you whether something will succeed. All you can do is try it, and see what happens. So, to a certain extent, the technique shown in the OP is the best way to go.