August 1999 Perl Hardware Store Slide #22

         $FILE = '/data/hitcounter';
         $SEMAPHORE = $FILE . '.lck';
         print "Content-type: text/html\n\n";
         open S, "> $SEMAPHORE" or die ...;
         if (something()) {
           flock S, LOCK_SH;
           open F, $FILE or die ...;
           print while <F>;
         } else {
           flock S, LOCK_EX;
           open F, "> $FILE" or die ...;
           my $data = qx{some command};
           print F $data;
         }
         close F;  close S;


Next Copyright © 1998 M-J. Dominus