Programming Wiki: Perl: Writing to a file with a lock file

Programming Wiki : PerlWritingToFile

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Perl: Writing to a file with a lock file

Perl


# create a lock file
$lockfile="lock_the_file.loc";
while (-e $lockfile) {
 sleep 2;
}
open (LOCK,">$lockfile") || die ("Cannot open lock file!\n");
close (LOCK);

# write to the data file
open(FOUT,">$myfile") || die("Cannot Open File");
print FOUT "String to put in file\n";
close(FOUT);

# delete the lock file
unlink($lockfile);

There are no comments on this page. [Add comment]

Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.0149 seconds