[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-WebCGI] "flock" question



I'm pretty new to Perl and have been picked up quite a bit of knowledge just 
from reading the various macperl mailing lists. I've reached a the point, 
however, where I have to ask for help.

As a simple way to get some practice, I've been playing with the simple 
guestbook program in Chapter 19 of "Learning Perl." I've installed the file 
as a CGI script in the cgi-bin folder of my server. When I try to access the 
script from my browser, I get the following message:

# The flock() function is unimplemented.

Relevant code follows:

========

....
use 5.004
use strict;
use CGI qw(:standard); 
use Fcntl qw(:flock);   # imports LOCK_EX, LOCK-SH, LOCK_NB
...
#get exclusive lock on the guestbook (LOCK_EX == exclusive lock)
flock(CHANDLE, "+< $CHATNAME || bail ("cannot open $CHATNAME: $!");

========

"Learning Perl" notes the use of Perl 5.004 and says:

 "If you want to run it with an earlier version of Perl 5, you'll need to 
comment out the line reading:

   use Fcntl qw (:flock);

and change LOCK_EX in the first flock invocation to be 2." 

I have attempted this fix, without success. If I comment out the call to 
flock completely, the script runs, although the file used to store guestbook 
entries fills up with garbage. (Lots of *long* strings filled with 
"%00%00%00%00".) This is unacceptable, obviously, both because of the garbage 
and the need to have only one person changing the file at a time.

I'm taking a Perl class at an institution which has Perl running under Linux. 
I've gotten the script to run successfully on that machine without 
modification (other than the call to Perl at the top, of course). My question 
is: Does MacPerl implement flock? If so, how do I access it? If not, I assume 
"there's more than one way to do it." Does anyone have any suggestions as to 
how?

Thanks,

Bill

--------------------

"The difference between theory and practice is that in theory the difference 
doesn't matter, while in practice it does."

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org