Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re-runnably editing a file in place

by Bilbo (Pilgrim)
on May 22, 2003 at 09:54 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found