tags:

views:

925

answers:

3

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 a Perl n00b get this up and running easily?

+6  A: 

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.

Paul Beckingham
+1  A: 

thanks. I installed strawberry and that worked.

FYI. This is the code in the script that ActivePerl didn't like.

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

gbjbaanb
What was the error message?
brian d foy
Also, if you need to clarify or expand your question, edit the question instead of adding an answer :)
brian d foy
But that doesn't apply to comments? :)
ysth
'install strawberry' is an actually an answer :) I'll revisit it sometime and try with ActivePerl and report back on the error message - it was quite clear though, beforehand I didn't know what flock or fcntl was. It barfed on the use statement though, and ppm didn't contain a fcntl option.
gbjbaanb
That's a correct "use" statement, so it sounds like your ActivePerl distribution either did not have Fcntl installed or it wasn't installed properly.
Max Lybbert
+1  A: 

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'}")