in reply to Re: Multiple Acess to a single file
in thread Multiple Acess to a single file

Hi All, My apologies for not being here for a while. Thank you all for showing me directions to my concerns. i will now share snippet of my code (which is not working yet). As of now i have five lines in the text file, wherein each perl process has to execute only one line upon meeting the conditions i.e "it should match the line which has the word pending". P.S Somehow when i post this script all the indentation vanishes.apologies for that. My script
use Fcntl qw(:flock :seek); my $myfile = "C:\\ssk\\A.txt"; open(MYFILE, $myfile) or die; undef $/; flock(MYFILE, 1); foreach my $line (<MYFILE>) { $line =~ /(\w*):(\w*):(\w*)/g; my $status = $3; if (($3 ne "done") || ($status ne "inprogress")) { # do nothing } } close MYFILE; open(MYFILE, "+< $myfile") || die; flock(MYFILE, 2); my @content = <MYFILE>; my $inprogress = "inprogress"; foreach my $line (@content) { $line =~ m/(\w*):(\w*):(\w*)/; if ($3 eq "pending") { $line=~ s/pending/inprogress/; seek(MYFILE, 0, SEEK_END); print MYFILE "$line"; splice(@content,0,1); } } close MYFILE; Contents of text file ===================== cmd:doscommand1:pending cmd:doscommand2:pending cmd:doscommand3:pending cmd:doscommand4:pending cmd:doscommand5:pending

Please let me know if i am on the right track, since the script is not working yet.. Do i still need to go ahead with DBMS.

thanks Sachu