Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Re-runnably editing a file in place

by Bilbo (Pilgrim)
on May 22, 2003 at 09:54 UTC ( #260017=note: print w/replies, xml ) Need Help??

in reply to Re-runnably editing a file in place

I think that the most reliable sequence would be:

  1. Edit the file, reading from the original, writing to the temporary file
  2. Set the permissions on the temporary file to those of the original file
  3. Rename the temporary file to the original filename.

Unless there is an interuption during the final renaming of the file your file should be in a sensible state whatever happens.

Update: Sorry, that's what you're doing already, with the necessary step of making the file readable to move it. I'm not very awake at the moment. Just ignore me.

I'm not sure if there would be any advantage in using the move function in File::Copy rather than rename. Is it more portable or reliable?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-07-18 04:40 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (383 votes). Check out past polls.