#!/usr/bin/perl use FileHandle; use Fcntl ':flock'; # Create file handle and open file for writing # my $fh = new FileHandle; if ($fh->open(">file")) { # Obtain an exclusive lock on the file handle # flock ($fh, LOCK_EX); # Write to file handle # print $fh "Just another Perl hacker\n"; # Remove exclusive lock on file handle and close file handle # flock ($fh, LOCK_UN); $fh->close; } exit 0;