CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
flock and $^I

 



xMattHawkx
stranger

Jun 21, 2001, 2:23 PM

Post #1 of 5 (1326 views)
flock and $^I Can't Post

I was just wondering if it is possible to use flock while doing an inplace edit. I have 4 scripts that access (via inplace edits) a database (flatfile) and I'm beginning to belive that when the file is modified more than once at the same time, parts of the file get deleted. I've been monitoring my log file I created (keeps track of file changes and database size in bytes) and everything is normal, but sometimes, I will see a drastic change in file size which I belive occurs when the file is modified more than once at the same time. Sooo...I think that if I could use flock i could solve the problem. Thanks for your time :).



Mortimer
journeyman

Jun 21, 2001, 10:48 PM

Post #2 of 5 (1311 views)
Re: flock and $^I [In reply to] Can't Post

Hello again xMattHawkx. I don't know the answer for sure, but remember that your original file is renamed to it's original name, along with whatever you've assigned to $^I tacked on to the end. The file that is written to is dealt with through the ARGV file handle. You can explicitly create the new file with ARGV, and you don't have to give it the file name...


Code
my $filename = "/path/to/data.txt"; 

@ARGV = ($filename);
$^I = ".bak";

open( ARGV );
while(<ARGV>){
s/(.*)/$1\n26\|Testing 123/ if eof;
print;
}

...so, although I don't know for sure, I assume you could...


Code
flock( ARGV, 2 ); 
...

...just like a normal file open. If you test it, please let me know because I havn't tested this on my unix yet. And by the way, there's no need to scope $^I or @ARGV as they're special.

Cheers,
Dave.
www.dmscripts.com
davemortimer@bigpond.com




xMattHawkx
stranger

Jun 22, 2001, 4:32 PM

Post #3 of 5 (1294 views)
Re: flock and $^I [In reply to] Can't Post

I wish I had a way to test it....my database is accessed all the time by nearly 3000 people...and when something goes wrong its a whole lot of complaining...

I can't test in on my test file as i have no way of accessing it multiple times and if I tried it on my real database...even though i back it up...by the time i backed up the latest info, the file will have already been accessed and changed again.



xMattHawkx
stranger

Jun 22, 2001, 6:43 PM

Post #4 of 5 (1287 views)
Re: flock and $^I [In reply to] Can't Post

Hehe..I just tested it, the $hit hit...

It wiped almost my entire database, it left only the first like 30 lines... and they were all cut off at diffrent points. Luckly I had a new backup... :).



xMattHawkx
stranger

Jun 24, 2001, 6:21 PM

Post #5 of 5 (1279 views)
Re: flock and $^I [In reply to] Can't Post

Would anyone have any idea why accessing a file at the same time using 4 diffrent scripts via inplace edits would delete huge chunks of a file?


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives