Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to repeat a string multiple times if found match

by GrandFather (Saint)
on Mar 09, 2021 at 02:35 UTC ( [id://11129360]=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found