simonodell has asked for the wisdom of the Perl Monks concerning the following question:
My question is, how should I modify these in order to avoid lockups when multiple users are attempting to read/write the same files? is there some way perhaps to shunt off the writing to a background process?sub getFile { my $fileName = shift(@_); unless ($gotFiles->{$fileName}) { undef $/; open $file, $fileName; my $buf = <$file>; close $file; $gotFiles->{$fileName} = $buf; } return $gotFiles->{$fileName}; } sub writeFile { my $data = shift(@_); if ($data =~ m@<filename>(.*?)</filename>@s) { $filename = $1; } if ($data =~ m@<data>(.*)</data>@s) { $filedata = $1; } open(DAT,">$ENV{DOCUMENT_ROOT}/$filename") || return 0; print DAT $filedata; close(DAT); $gotFiles->{"$ENV{DOCUMENT_ROOT}/$filename"} = $filedata; return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file reading / writing collisions
by ikegami (Patriarch) on Sep 11, 2007 at 04:37 UTC | |
by simonodell (Acolyte) on Sep 11, 2007 at 07:46 UTC | |
by sgt (Deacon) on Sep 11, 2007 at 13:41 UTC | |
by ikegami (Patriarch) on Sep 11, 2007 at 13:42 UTC | |
|
Re: file reading / writing collisions
by kyle (Abbot) on Sep 11, 2007 at 03:30 UTC |