sachu has asked for the wisdom of the Perl Monks concerning the following question:
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.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
thanks Sachu
Hi All, I have a query in Perl. IS it possible for me to access and modify a single text file through PERL programmes. Can you please provide pointers on how to achieve this. Ok Let me make it more clear ... Let me give you all a brief scenario of what my intentions are. What i am trying to do is,i have to run multiple perl programmes all at once to change the contents of a text file. and the text file would contain 2 things. Test name and status. So as i run multiple perl programmes, i want each prgm to read single line at once and check the status. if the status is pending , change status to inprogress execute that line, and then change the status to done and come out of the programme, else skip to the next line till it finds pending. Just wanted to make sure, this would give access denied error, as the file would be used by another programmes. Hope that helps. Regards, SSK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple Acess to a single file
by psini (Deacon) on Aug 29, 2008 at 23:03 UTC | |
by sachu (Initiate) on Sep 03, 2008 at 21:23 UTC | |
|
Re: Multiple Acess to a single file
by ww (Archbishop) on Aug 29, 2008 at 23:10 UTC | |
|
Re: Multiple Acess to a single file
by SilasTheMonk (Chaplain) on Aug 29, 2008 at 23:25 UTC | |
|
Re: Multiple Acess to a single file
by shmem (Chancellor) on Aug 29, 2008 at 23:42 UTC | |
by sachu (Initiate) on Sep 03, 2008 at 20:22 UTC | |
|
Re: Multiple Acess to a single file
by eosbuddy (Scribe) on Aug 29, 2008 at 23:32 UTC | |
|
Re: Multiple Acess to a single file
by hangon (Deacon) on Aug 30, 2008 at 08:15 UTC |