Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Write to existing file with character insert

by zwon (Abbot)
on Oct 24, 2012 at 16:16 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-25 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found