Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: changing data

by krujos (Curate)
on Aug 30, 2002 at 16:20 UTC ( #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.


Comment on Re: changing data

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-07-14 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls