Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Perl
Expertise: Intermediate
Jun 22, 2004



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Write to a Perl File Using Flock

In his tip "Locking a File With the Perl Flock Function," Steve Renaker's example opens a file without specifying read or write. While this will successfully open a file for reading, the context of this example (indeed the very reason for using flock in the first place) involves writing to a file:

open (FILE, ">data.txt");
flock (FILE, 2);
Now, the file is available for writing. In the original example, the file was indeed locked so no other script could write to it, but the example code would not be able to write to it either.

Jaime Bellmyer
Thanks for your registration, follow us on our social networks to keep up-to-date