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: Intermediate:
Flock with Win and Unix

 



benchivers
Novice

Mar 17, 2003, 3:54 AM

Post #1 of 5 (490 views)
Flock with Win and Unix Can't Post

What is the system acquivalent of the flock command for WinNT?

Does WinNT need file locking, when this file could be read by many people at one time? Is there a chance the file could be corrupt?

Many Thanks,

Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!


davorg
Thaumaturge / Moderator

Mar 17, 2003, 5:10 AM

Post #2 of 5 (485 views)
Re: [benchivers] Flock with Win and Unix [In reply to] Can't Post

You do need to "flock" file on WinNT. You do it using "flock" in exactly the same way as you do on Unix.

Some versions of WinNT doen't implement a native version of "flock" (why? who knows!) but in those cases recent versions of ActivePerl will simulate "flock" for you.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Paul
Enthusiast

Mar 17, 2003, 7:00 AM

Post #3 of 5 (484 views)
Re: [benchivers] Flock with Win and Unix [In reply to] Can't Post

If you aren't using the latest version of perl you will either need to upgrade or leave out the flock call. You could also do:

flock(FH, 2) unless $^O eq 'MSWin32';

...which says to call flock unless we are on a windows platform. Or you can "fake" flock using:


Code
BEGIN { 
if ($^O eq 'MSWin32') {
*CORE::flock = sub { 1 };
}
};


..that will allow you to call flock as normal without having to include "unless $^O eq 'MSWin32'" for every call.


benchivers
Novice

Mar 17, 2003, 8:30 AM

Post #4 of 5 (480 views)
Re: [Paul] Flock with Win and Unix [In reply to] Can't Post

Hi,



Thanks for both replies. I was almost certain WinNT didn't support the 'flock' command, I thought it was purely Unix based. I have one more question though, I have noticed the 'require' function command doesn't work in WinNT on the web server I am using, is it supported on this operating system or only Unix?

Cheers,

Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!


davorg
Thaumaturge / Moderator

Mar 18, 2003, 1:25 AM

Post #5 of 5 (477 views)
Re: [benchivers] Flock with Win and Unix [In reply to] Can't Post

"require" works on all platforms. What code are you having trouble with and what error messages are you seeing?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


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

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