in reply to Faster locking

You don't check whether a) the open b) the flock c) the close of filehandle FLOCK are successful, you don't check the unlink, so your script just silently ignores any misdeeds and whistles along, and you get no clue about what's going on.

To avoid creating/removing the lockfile (takes time, too), you could just lock the script itself, using the DATA filehandle:

if ($cached == 0) { exit unless flock(DATA, LOCK_EX | LOCK_NB); ... flock(DATA, LOCK_UN); } ... __END__ __DATA__

The LOCK_NB is there so the script doesn't wait until a lock is granted.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'