Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194159]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-06-18 10:29 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.