in reply to Re: File opening/creating
in thread File opening/creating

Oh, that's a great point. The basic problem is that if the file does exist but cannot be opened for reading, yet can be opened for output, my method will clobber what's there and then continue looping forever.

I suppose that's why I should have just used the '-e' function:

if ( -e $filename ) { open FH, "<$filename" or die $!; } else { open FH, ">$filename" or die $!; close FH; open FH, "<$filename" or die $!; }

At least this eliminates the potential for the endless loop.


Dave

Replies are listed 'Best First'.
Re: File opening/creating
by Abigail-II (Bishop) on Mar 03, 2004 at 23:09 UTC
    The potential problem here is that you might wipe out data created by another process. Testing for existance and the following open aren't atomic, and a lot of things can happen in between.

    Really, do use sysopen. That's atomic.

    Abigail