in reply to Re: error message not working
in thread error message not working

Ah yes. On some operating systems, you can only do a LOCK_EX on a handle that's open for writing. DATA is open for reading only. I guess that is why the original fails, and your version works.

Update: perldoc -f flock has this to say about it:

Note that the emulation built with lockf(3) doesn't provide shared locks, and it requires that FILEHANDLE be open with write intent. These are the semantics that lockf(3) implements. Most (all?) systems implement lockf(3) in terms of fcntl(2) locking, though, so the differing semantics shouldn't bite too many people.
That must be the case, here. "Not too many people", right.