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

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-04-24 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls