in reply to How to repeat a string multiple times if found match

Your mistake is not formatting your question so that we can read it.

Your coding mistake is mixing reading and writing to the file at the same time. You read a line then write a line overwriting content in the file that followed the content you just read. This would be more obvious if you mixed up line lengths more.

Usual practice is to create an output file to write the updated content to, then after the update is complete delete the old file and rename the new version to the name of the old version.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
  • Comment on Re: How to repeat a string multiple times if found match

Replies are listed 'Best First'.
Re^2: How to repeat a string multiple times if found match
by haukex (Archbishop) on Mar 09, 2021 at 08:04 UTC
    Usual practice is to create an output file to write the updated content to, then after the update is complete delete the old file and rename the new version to the name of the old version.

    suvendra123: You may be interested in my module File::Replace to help you with this.

      I don't want foo_ foo line only
      foo_1 foo_2 foo_3
        I don't want foo_ foo line only foo_1 foo_2 foo_3

        Please compare your code to the code I gave you here.