Hi All,
I have a query on Perl. I have a text file which has 3 lines, i want to only replace the first line with my replaced text and keep the rest of the text. FOr eg
Before change -->
echo:a
ending
echo
pending
echo:c
ending
After change --->
echo:a:done
echo
pending
echo:c
ending
Brief: Here i am continuously trying to modify the text file though this perl programme from multiple machines i.e this perl prog will run on multiple machines trying to modify\change a single text.
Snippet of my code.(not working yet. It appends to the text file instead of replacing it). Can you please guide me to this.
============================================
open(MYFILE, "+< $myfile") || die;
flock(MYFILE, 2);
#my $myfile="c:\\ssk\\help.txt";
#open INPUT, "<$myfile";
undef $/;
my $content = <MYFILE>;
my $inprogress = "inprogress";
my $done = "done";
$content =~ m/(\w*)
\w*)
\w*)/;
if ($3 eq "pending")
{
$content=~ s/pending/inprogress/;
my $contentbkup = $content;
$content =~ s/(.*)//g;
print MYFILE "$1";
print MYFILE "$contentbkup";
$contentbkup =~ s/(.*)
.*)
.*)/(.*)
.*):$done/;
}
seek(MYFILE, 0, 0);
close MYFILE;
$/ = "\n";