in reply to Read strings from a file, search and replace same string in another file.

Lets analyze your script: First it slurps the contents of FILE2 into memory which means the file pointer is at EOF (= End Of File). In the inner loop it tries to read a line from FILE2 (file pointer at EOF, so no go) and then tries to write that line directly after its original place in the same file! Also it tries to write into a file that is opened for reading.

What seems to be missing is a line where you open FILE2 for writing (somewhere after you have read its contents). Also the inner loop has to loop over @file2, not <FILE2>

  • Comment on Re: Read strings from a file, search and replace same string in another file.
  • Download Code

Replies are listed 'Best First'.
Re^2: Read strings from a file, search and replace same string in another file.
by Anonymous Monk on Dec 09, 2011 at 05:13 UTC

    Thanks for your reply. I did open my file for read write but dont know how it got changed while copying my code. Finally I was able to get my work done. Thanks again for your help.