in reply to Re: TIMTOWTDI Challenge: Open a file
in thread TIMTOWTDI Challenge: Open a file

oooo....i like that...that's pretty...and clean.

my question is...what kind of modules are there for operating systems that don't support file locking?

I know there's quite a few methods for checking and adapting for such, but has anyone put together a module encompassing these routines?

meh.

Replies are listed 'Best First'.
Re^3: TIMTOWTDI Challenge: Open a file
by xdg (Monsignor) on Apr 28, 2006 at 00:25 UTC

    According to perlport, flock is available on WinNT (and later). You should be able to check Config for d_flock.

    > perl -MConfig -le "print $Config{d_flock}" define

    No guarantees on how good that is for protecting against anything other than other Perl programs using flock. You might have to use Win32API::File for more direct control.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^3: TIMTOWTDI Challenge: Open a file
by ikegami (Patriarch) on Feb 10, 2009 at 20:33 UTC

    Windows supports both advisory and mandatory file locking, and can perform a non-blocking lock check.

    It even uses mandatory exclusive locks by default. You can relax the lock and allow others to do any combination of the following: delete the file (FILE_SHARE_DELETE), read from the file (FILE_SHARE_READ) and write to the file (FILE_SHARE_WRITE).

    Finally, Perl's flock works perfectly fine in Windows, including LOCK_NB.