Open write mode for flock(fh, LOCK_EX) for portability

We should open file with write intent for using flock(fh, LOCK_EX) for portability. Because flock(fh, LOCK_EX) is failed without write intent on some platforms(such as Solaris) and platforms which does not provide flock. (In this case Perl emulates flock with other API).

On Linux or some BSD(include MacOSX), flock(fh, LOCK_EX) successes without write intent. However if you want to work your module on many platforms, you should open with write intent.

perldoc -f flock says

Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE be open with read intent to use LOCK_SH and requires that it be open with write intent to use LOCK_EX.

See also