Help for this page

Select Code to Download


  1. or download this
    open my $FH, ">the_file"; # zero-byte the file
    flock($FH, LOCK_EX);      # and Then lock it...
    
  2. or download this
    open my $FH, "the_file";   # open for reading
    flock($FH, LOCK_SH);       # lock it
    ...
    push @lines, "new line\n"; # process the lines
    print $FH for (@lines);    # write them out
    close $FH;                 # close and drop lock
    
  3. or download this
    
    # Open a different file as a semaphore lock
    ...
    close $FH;                 # close the file
    
    close $SEM;                # close and unlock semaphore
    
  4. or download this
    
    # Open the file for locking purposes only
    ...
    close $FH;
    
    close $SEM;                # close and unlock semaphore