All-knowing monks
I have these two routines;
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;
}
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?