kkavitha has asked for the wisdom of the Perl Monks concerning the following question:

I have a subroutine which is interact with external file. How to make I this subroutine to synchronize? I am using in the following.

Example: $isAllowed = checkAndAllowed($pdt);

This checkAndAllowed($pdt) subroutine will rewrite the content of external file

If anyone knows, please share it here

Thanks in Advance, Kavitha

Replies are listed 'Best First'.
Re: How to synchronize the one subroutine
by cdarke (Prior) on Sep 11, 2009 at 11:17 UTC
    I'm not sure exactly what you are looking for. What is it that you want to synchronize your subroutine with?

    Maybe you want to flush the buffers of the external file? Look at $| in perlvar, but closing the file would do that.

    Maybe you have other scripts you need to synchronise with. Look at flock (UNIX/Linux) or Win32::Mutex (Windows), or maybe other IPC mechanisms.

      flock works fine on Windows too

      Thanks for your information

      One of the subroutine of our tool is exposed with external file like writing, rewriting, remove entry. Currently, when multiple user tried to use this tool at the same time, external file content has changed irrelevently. My requirement, external file should be edit by only one user at a time

Re: How to synchronize the one subroutine
by Anonymous Monk on Sep 11, 2009 at 11:25 UTC