Help - Search - Member List - Calendar
Full Version: flock and open files
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Bclark1
Hi list

My colleaque and I have just had a small disagreement with each other
about file locking and reading / ammending a txt file.

To up date a CSV file (it must be quick and / or effient), my colleaque
likes to either read the whole file in memory (I dont like this) or
open the file and use seek etc.

I like to open the file, open a tem, use a while, print the line to the
temp file, and on the line im looking for do what I need then print to
the temp file and then close the file and then unlink the original and
then rename the file.

The other one is file locking. My colleaque says the flocking does not
work on Linux, where as I say the flock works for both Linux as well as
win32. I read the perldocs and I have not seen anything proving him
right, but as the same time I have not seen anything that proves him wrong.

So if anyone share their experiences or tips is would be most appreciated.

Please bare with me on this, still new to perl / programming.

Kind Regards
Brent Clark

----- Original Message -----
From: bclark1 <[Email Removed]>
Date: Thursday, July 14, 2005 6:48 am
Subject: flock and open files

QUOTE
Hi list
Hello,

My colleaque and I have just had a small disagreement with each
other
about file locking and reading / ammending a txt file.

To up date a CSV file (it must be quick and / or effient), my
colleaquelikes to either read the whole file in memory (I dont
like this) or
open the file and use seek etc.

I like to open the file, open a tem, use a while, print the line
to the
temp file, and on the line im looking for do what I need then
print to
the temp file and then close the file and then unlink the original
and
then rename the file.
This is just a choise of preferance, as long as you can be certain that no other processes are modifying the file while you are at it, techniqe makes no differance [ surly one will be faster and more secure then other ].


QUOTE

The other one is file locking. My colleaque says the flocking does
not
work on Linux, where as I say the flock works for both Linux as
well as
win32. I read the perldocs and I have not seen anything proving
him
right, but as the same time I have not seen anything that proves
him wrong.
reading perldoc -f flock...


" Calls flock(2), or an emulation of it, on FILEHANDLE. Returns
true for success, false on failure. Produces a fatal error if
used on a machine that doesn't implement flock(2), fcntl(2)
locking, or lockf(3). "flock" is Perl's portable file locking
interface, although it locks only entire files, not records."

Sounds like any OS that supports these system calls, will work. Surely most [ I have never herd of one] linux systems will support these system calls. you should also know that <C>flock will not actualy lock the file, just set locking bit on.

QUOTE
So if anyone share their experiences or tips is would be most
appreciated.
Please bare with me on this, still new to perl / programming.

Kind Regards
Brent Clark
Cheers,

mark G.
QUOTE

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response





PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.