Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Write to existing file with character insert

by zwon (Abbot)
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.

Replies are listed 'Best First'.
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]
[Discipulus]: as a greed Agrid I agree.. coffee!

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-05-21 08:22 GMT
Find Nodes?
    Voting Booth?