Hi Luinrandir, > Anyone know about this? or can I just: > #Open to read > open (DataFile, "$_[0]")||die "Sorry, I can't open $_[0]\n"; > flock (DataFile,2); > @Data =<DataFile>; > #open to write > open DataFile, ">$_[0]")||DieNice3("Can't write to $_[0]"); > flock (DataFile,2); > foreach $Data(@Data) > { > print DataFile "$Data\n"; > } > close (DataFile)||die "Sorry, I can't close $_[0]\n";
Reading and writing files from CGI scripts can be tricky due to "race conditions". A race condition occurs when more than one process is trying to do something but the data corruption can occur if they do those things in the wrong order. So let us say you want to 1. open a file 2. flock it 3. write to it 4. close it Now let's say another process tries to read that file but does so after the first process executes step one and before it executes step two. The second process will be trying to read an apparently empty file. "sysopen' actually allows you to open and lock the file at the same time, but this is not supported on all systems. For a clean way of handling this by using what are known as "semaphore" files, read "Resource locking with semaphore files" (http://interglacial.com/~sburke/tpj/as_html/tpj23.html) Cheers, Ovid ===== Silence is Evil http://users.easystreet.com/ovid/philosophy/decency.html Ovid http://www.perlmonks.org/index.pl?node_id=17000 Web Programming with Perl http://users.easystreet.com/ovid/cgi_course/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>