Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Cleaner way of looping through a file and stripping only certain lines?

by jbert (Priest)
on Dec 08, 2006 at 18:22 UTC ( [id://588667]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Cleaner way of looping through a file and stripping only certain lines?
in thread Cleaner way of looping through a file and stripping only certain lines?

The safer way to do this sort of thing is to write to a new file and then rename over the file you want to replace. This is what you do when handling mbox files for instance.

The rename is an atomic operation. It's guaranteed to succeed completely or not at all (on Unix-like boxes), so you can never lose data as a result of a power failure.

This is a similar trick to perl -i, but I think that does a rename of the original file and then writes back into the original file, which still leaves open the case that you could have bad (partially written) data in the original file on power failure.

  • Comment on Re^3: Cleaner way of looping through a file and stripping only certain lines?
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found