Home: Perl Programming Help: Intermediate:
Flock: Unlock before close?



gregarios
stranger

Feb 12, 2002, 1:25 PM


Views: 1148
Flock: Unlock before close?

When using flock, is there any reason why you would want to unlock a file right before closing it? Or is closing it without unlocking it better?


yapp
User

Feb 13, 2002, 3:33 AM


Views: 1141
Re: [gregarios] Flock: Unlock before close?

perl as of version 5.4 doesn't require a unlock before closing.

I thought that the close() function also flushes all buffers. If that's true for filehandles, It means that there could still be data written to the file when the close() function is called. So for that case, It would be better not to unlock the file before closing it.

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool


gregarios
stranger

Feb 13, 2002, 9:09 AM


Views: 1137
Re: [yapp] Flock: Unlock before close?

What if I have Perl 5.00503?


yapp
User

Feb 13, 2002, 9:20 AM


Views: 1134
Re: [gregarios] Flock: Unlock before close?

Sorry. I ment perl 5.004 So your per version is actually higher.

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool


gregarios
stranger

Feb 13, 2002, 9:22 AM


Views: 1132
Re: [yapp] Flock: Unlock before close?

Thank you very much. :-)


rGeoffrey
User / Moderator

Feb 19, 2002, 9:30 PM


Views: 1121
Re: [gregarios] Flock: Unlock before close?

I also just close the file without releasing the lock. But I know of one good programmer who insists that you should explicitly close it. His argument is that someone may add extra code later and the close will get too far from the open and locking and you might forget about the lock. Just an extra reminder to close files as soon as possible to avoid bad things from happening.


Paul
Enthusiast

Feb 20, 2002, 2:27 AM


Views: 1117
Re: [rGeoffrey] Flock: Unlock before close?

>>
But I know of one good programmer who insists that you should explicitly close it.
<<

close FH; automatically opens the lock.


(This post was edited by RedRum on Feb 20, 2002, 2:28 AM)


yapp
User

Feb 20, 2002, 9:03 AM


Views: 1110
Re: [rGeoffrey] Flock: Unlock before close?

I've been looking about the thing I mentioned above:

- the close() function flushes all buffers, so there could still be data written to the file.
- that means you shouldn't unlock it earlier. So let Perl the job for you.

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool