CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Locking files

 



Nicko
Deleted

Jul 3, 2000, 12:50 PM

Post #1 of 4 (998 views)
Locking files Can't Post

Hi am new to the forums. I have been programming in PERL for about a year now and I have failed to find very much information about locking down files. In the PERL Cookbook it talks extensively about using FLOCK, but I have seen other PERL programmers who do not use FLOCK, but instead write their own flocking routine. Typically they create a temp file, work with that file and then the drop the lock. Two specific examples I am thinking of our Matt wrights counter script, and bignosebird.com uses his own file locking routine instead of using FLOCK. My question is: is there an advantage to using FLOCK as opposed to writting your own file locking routine?

------------------
Best regards,

Nicko
www.cheftalk.com
"A food lover's link to professional chefs"


dws
Deleted

Jul 3, 2000, 7:48 PM

Post #2 of 4 (998 views)
Re: Locking files [In reply to] Can't Post

To begin, Matt Wright scripts are hardly examplars of Perl programming. You'll get a lot more mileage studying Randal Schwartz's scripts from his columns. Dig through http://www.stonehenge.com/ to find them.

Not all operating systems support flock. There's no flock on Windows 95/98, so scripts that seek to be portable need to fall back on a manual scheme.

If the OS supports it, flock is more effecient (and robust) than mucking about with creating temporary files or directories. Since the kernel already has a data structure to represent "open" files, twiddling some bits within that structure to "lock" the file is considerably more effecient than all of the overhead (disk I/O) involved in creating a new file.



errr
Deleted

Jul 5, 2000, 7:30 PM

Post #3 of 4 (998 views)
Re: Locking files [In reply to] Can't Post

First off, its Perl or perl.. not PERL. Perl refers to the language, perl to the interpreter itself. PERL is just ugly looking. Yes, I know its an acronym but so is radar and laser, but we don't go crazy with the caps lock on them either.
Second, this belongs in beginner or intermediate.. how is a question on a built in function advanced...
flock is the best when avail. Remember than many lock files are race conditions. Also remember that Matt Wright himself admits that his coding is poor.


Nicko
Deleted

Jul 6, 2000, 5:16 AM

Post #4 of 4 (998 views)
Re: Locking files [In reply to] Can't Post

Interesting, I have heard of errors in his cgi cookbook, but I have never heard him make an open statement that his coding is poor.

Thanks for the tips, sorry this was not in the correct forum topic. I have checked out Stonehenge.com many times, and have always found good information. As far as file locking I was only able to find the use of flock.

perl...not PERL

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives