March 2002 Perl Hardware Store 20

4. Semaphore Files

         use Fcntl ':flock';
         if (something()) {
           open F, $FILE or die ...;
           flock F, LOCK_SH;
           print while <F>;
         } else {
           open F, "> $FILE" or die ...;
           flock F, LOCK_EX;
           my $data = qx{some command};
           print F $data;
         }


Next Copyright © 2002 M-J. Dominus