Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is flock() for Perl on Windows?

Tags:

perl

flock

fcntl

I have a Perl script that I'd like to run on Windows, using either Strawberry Perl or ActivePerl; I don't care which. This script however, uses flock() calls, which does not seem to be included in either of those versions of Perl.

Can anyone help get this up and running?

like image 789
gbjbaanb Avatar asked Jan 25 '09 00:01

gbjbaanb


2 Answers

Is the Fcntl module installed? Try this:

perl.exe -MFcntl -e 1

If it complains, you don't have the Fcntl module installed. If it doesn't complain, then you have access to Fcntl::flock, so put this in your script:

use Fcntl qw(:DEFAULT :flock);

and off you go.

like image 153
Paul Beckingham Avatar answered Nov 19 '22 06:11

Paul Beckingham


Try using perldoc -f flock to check the things are supported & then look into the given example to know the usage criteria of the function. Here copied from the perldoc:

C:>perldoc -f flock

 use Fcntl ':flock'; # import LOCK_* constant

 sub lock {
     flock(MBOX,LOCK_EX);
     # and, in case someone appended
     # while we were waiting...
     seek(MBOX, 0, 2);
 }

 sub unlock {
     flock(MBOX,LOCK_UN);
 }

 open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}") 
like image 24
user56950 Avatar answered Nov 19 '22 04:11

user56950