Ask a Question related to PERL Miscellaneous, Design and Development.
-
Matija Papec #1
File locking for all my needs
I thought this could be usefull to someone but before you use it bear in
mind its limitations,
- probably works as expected only on Linux and other *nix like systems
- only convenient for text files
- handling very large files is not efficient
- if it isn't there, file gets created (this is a feature actually)
- ?
Function can be used in two ways, I generally use second for log files and
first for all other purposes..
#1) managing whole file at once
my @txt;
my $fh = OpenLock('/tmp/testing.txt', \@txt);
print $fh "top line\n", @txt;
close $fh;
#2) append lines to file
my $fh = OpenLock('/tmp/testing.txt');
print $fh "bottom line\n";
close $fh;
sub OpenLock {
################################################## #############
#
# open rw, flock, fill @$ra, truncate file to zero, return FH
#
################################################## #############
my($file, $ra) = @_;
local *FH;
open FH, "+>>$file" or die $!;
flock(FH, 2); #exclusive_lock
if ($ra) {
seek(FH, 0, 0);
@$ra = <FH>;
seek(FH, 0, 0);
truncate(FH, 0);
}
return(*FH);
}
--
Matija
Matija Papec Guest
-
File locking in XP
The issue i'm experiencing may be more related to XP Pro than with Illustrator itself, but it only seems to be affecting Illustrator EPS files... ... -
Win 2K3 & File Locking
Anyone aware of file locking issues specific to Perl on Windows 2003 server? -
Confused about locking a file via file.flock(File::LOCK_EX)
I am writing a ruby appl under AIX where I need to update the /etc/hosts table. I would like to make sure that during my update nobody else can... -
Locking File
Hello, I am opening a file like below: FileStream fs = File.Open(Server.MapPath("../Data/REFCOD.txt"),FileMode.Open,FileAccess.Writ... -
file locking
Hi All, There are 3 different file locking mechanisms in C: flock lockf fcntl I want to write a Ruby script, which shares files with a C...



Reply With Quote

