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: Unlock before close?

 



gregarios
stranger

Feb 12, 2002, 1:25 PM

Post #1 of 8 (551 views)
Flock: Unlock before close? Can't Post

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?

Greg J Piper
[url=http://www.macpicks.com]MacPiCkS



yapp
User

Feb 13, 2002, 3:33 AM

Post #2 of 8 (544 views)
Re: [gregarios] Flock: Unlock before close? [In reply to] Can't Post

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

Post #3 of 8 (540 views)
Re: [yapp] Flock: Unlock before close? [In reply to] Can't Post

What if I have Perl 5.00503?

Greg J Piper
[url=http://www.macpicks.com]MacPiCkS



yapp
User

Feb 13, 2002, 9:20 AM

Post #4 of 8 (537 views)
Re: [gregarios] Flock: Unlock before close? [In reply to] Can't Post

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

Post #5 of 8 (535 views)
Re: [yapp] Flock: Unlock before close? [In reply to] Can't Post

Thank you very much. :-)

Greg J Piper
[url=http://www.macpicks.com]MacPiCkS



rGeoffrey
User / Moderator

Feb 19, 2002, 9:30 PM

Post #6 of 8 (524 views)
Re: [gregarios] Flock: Unlock before close? [In reply to] Can't Post

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

Post #7 of 8 (520 views)
Re: [rGeoffrey] Flock: Unlock before close? [In reply to] Can't Post

>>
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

Post #8 of 8 (513 views)
Re: [rGeoffrey] Flock: Unlock before close? [In reply to] Can't Post

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

 
 


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

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