Hi, Perl is new to me. I am trying to insert a line to a file. Ex: I have a file (trial.txt), content:
ZZZZ
AAA
DDDD
I am trying to insert CCC below AAA.
MY perl command:
The ouuput I get:
ZZZZ
AAA
DDDDZZZZ
AAA
CCC
Where else what I need is:
ZZZZ
AAA
CCC
DDDD
It appends the whole file again and replaces the next line after AAA with CCC, where else what I need is to insert CCC in the existing file below AAA. Thanks to advise. :)
ZZZZ
AAA
DDDD
I am trying to insert CCC below AAA.
MY perl command:
Code:
open (FILE,"+>>C:\\Documents and Settings\\trial.txt\n")|| die "can't open file";
while(<FILE>)
{
if(/AAA/)
{
print FILE "CCC\n";
}
}#end while
close(FILE);
ZZZZ
AAA
DDDDZZZZ
AAA
CCC
Where else what I need is:
ZZZZ
AAA
CCC
DDDD
It appends the whole file again and replaces the next line after AAA with CCC, where else what I need is to insert CCC in the existing file below AAA. Thanks to advise. :)
Comment