Where is flock() for Perl on Windows?
Asked Answered
C

2

5

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?

Canonicate answered 25/1, 2009 at 0:26 Comment(0)
D
6

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.

Desmonddesmoulins answered 25/1, 2009 at 1:24 Comment(0)
E
1

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'}") 
Exhortation answered 25/1, 2009 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.