Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Inplace edit using XML::Twig

by kvale (Monsignor)
on May 22, 2006 at 03:40 UTC ( #550865=note: print w/replies, xml ) Need Help??

in reply to Inplace edit using XML::Twig

Why not just read in the file contents, truncate the file, and write processed file contents back out to the same file? No delete and rename needed.


Replies are listed 'Best First'.
Re^2: Inplace edit using XML::Twig
by gellyfish (Monsignor) on May 22, 2006 at 08:34 UTC

    There are two reasons, firstly renaming is an atomic operation on all the systems that I am aware of so there is no risk of another application that can't be made to co-operate with this one getting a partially written file, secondly writing to a second file mitigates against the risk of the file being corrupted if the process is interrupted due to a program or OS crash or hardware failure for instance. For the most part I would omit the deletion stage to further reduce the risk of losing the file (although some OS might not support this).


Re^2: Inplace edit using XML::Twig
by greenFox (Vicar) on May 22, 2006 at 08:07 UTC

    Tim Bray makes some suggestions why you might not want to do that here, the caveat being of course how important is the data in question.

    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-06-24 21:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.