mukeshbaranwal has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a file named testbed.cfg. It has some lines varname and value pair eg:- username = "mukesh" ; I want to open the file and then change the value under quote to another name like "sachin"; this change should be permanent. I am not able to modify this permanently. Please help me anyone. Thanks in advance. Mukesh Baranwal

Replies are listed 'Best First'.
Re: Modifying a file
by jethro (Monsignor) on Dec 17, 2010 at 11:51 UTC
    This question comes up quite often, for example change a line or string in file handles the same question and provides a few solutions. Also you could look into our FAQ.
Re: Modifying a file
by roboticus (Chancellor) on Dec 17, 2010 at 11:46 UTC

    mukeshbaranwal:

    What error messages are you getting? What have you tried? From your post, I'd guess that you're changing the data in memory, but not actually writing it to disk.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Modifying a file
by toolic (Bishop) on Dec 17, 2010 at 11:44 UTC
    Read perlintro then post some code that you have tried with a small sample (a few lines) of your input file. Then, try to describe in more detail what problem you are having.
Re: Modifying a file
by Anonymous Monk on Dec 17, 2010 at 11:47 UTC
    perl -i.bak -pE's/mukesh/munkfish/ if /^username = "mukesh"/' testbed.cfg