in reply to Re: Is something wrong with the below Script??
in thread Is something wrong with the below Script??

why another out File handler??,
is it not possible to open the same file and replace the sting and save in to it. I need to save in the same file only ..

Please help
  • Comment on Re^2: Is something wrong with the below Script??

Replies are listed 'Best First'.
Re^3: Is something wrong with the below Script??
by ig (Vicar) on May 19, 2009 at 04:37 UTC

    You might find seek helpful, and in particular this bit:

    Due to the rules and rigors of ANSI C, on some systems you have to do a seek whenever you switch between reading and writing.

    update: You should also think about what will happen to your file if you write directly to your original file and your modified string is shorter or longer than the original.

Re^3: Is something wrong with the below Script??
by Anonymous Monk on May 19, 2009 at 04:43 UTC
    Because its short, its easy to understand and it works. Editing a file in-place is possible, but its nontrivial. See Re: Edit File in place for some reasons why.
Re^3: Is something wrong with the below Script??
by apl (Monsignor) on May 19, 2009 at 08:31 UTC
    It's a good idea to rename your original file to a new name, and to then write out the new version of the file to the original name. This provides an audit trail, and helps to resolve pesky questions when a change you didn't want occurrs...