open will fail if there are no permissions, or the file does not exist, or something of the sort.
flock will fail if an error occured, or if a non blocking request for a lock failed. I assume that should the filehandle have not been opened by
open, then perhaps
flock will fail if there was an error anyway. But you'll probably lose the content of $!.
Opening a locked file will not raise an error, as on *nix locks are advisory, and not mandatory. Your open statement will actually fail only if you haven't read access to the file, or the directory in case it doesn't exist. Other than that there is no reasonably expectable error, and what you're trying to acheive is done, as the others noted, with non blocking
flock.
-nuffin
zz zZ Z Z #!perl