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

Re: changing data

by krujos (Curate)
on Aug 30, 2002 at 16:20 UTC ( [id://194159]=note: print w/replies, xml ) Need Help??


in reply to changing data

You need to write the file back out. What you have (assuming your regexp is correct and all of that) just changes the file in memory, not on the disk. It is also important to note that the global option is unnecessary in your situation (if your replacing a whole line why would you need to repeat). You will also replace oldline with new line other places in the file. If you have duplicate lines and want to keep some this will get hard for you.
That said here is a way to do this. You need to store all of the lines in memory (check out push for this), change the one you need and write it back to the file. Also you are just going to append to the file the way you have your code now. If that is your intention you have it correct, if not read the documentation on open You should also be closing the file, but you are probably doing that further down in your code.

Log In?
Username:
Password:

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

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

    No recent polls found