note
adamk
But wait, it gets better again!<br>
<br>
You know how you can have that nifty __DATA__ block at the end of your script? It turns out you can lock that too :)<br>
<br>
I've used this a number of times and it works just great.<br>
<br>
#!/usr/bin/perl<br>
<br>
use strict;<br>
use Fcntl 'LOCK_EX', 'LOCK_NB';<br>
<br>
unless ( flock DATA, LOCK_EX | LOCK_NB ) {<br>
print STDERR "Found duplicate script run. Stopping\n";<br>
exit(0);<br>
}<br>
<br>
...<br>
<br>
1;<br>
<br>
<br>
<br>
<br>
<br>
### DO NOT REMOVE THE FOLLOWING LINES ###<br>
<br>
__DATA__<br>
This exists to allow the locking code at the beginning of the file to work.<br>
DO NOT REMOVE THESE LINES!<br>
<br>
518170
518197