Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Write to existing file with character insert

by zwon (Monsignor)
on Oct 24, 2012 at 16:16 UTC ( #1000663=note: print w/ replies, xml ) Need Help??

in reply to Write to existing file with character insert

I'm struggling to work out how to successfully search and replace this string in the same file and save it off.

If you inserting or removing something from a file you have to rewrite all the file starting from the place where you're inserting or removing data. Therefore a practical approach is to read data from file, change it as needed, and save into a new file. Then rename new file to replace the original. You don't have to implement it yourself though, just use edit_file_lines function from the File::Slurp module.

Comment on Re: Write to existing file with character insert
Download Code
Re^2: Write to existing file with character insert
by Anonymous Monk on Oct 24, 2012 at 19:08 UTC
    ... unless you know and can guarantee that every single file you may be interested in will fit in the memory of the computers that you will be using to process them. Not a very safe assumption in the general case ... but maybe.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-03-07 02:10 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (183 votes), past polls