Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: read file line by line then do something and write to same file

by oiskuu (Friar)
on Jun 16, 2014 at 19:36 UTC ( #1090066=note: print w/ replies, xml ) Need Help??


in reply to Re^2: read file line by line then do something and write to same file
in thread read file line by line then do something and write to same file

A cursory strace perl -pi reveals a more sloppy pattern than described, however. I see open/unlink/open/read+write/close/close. The unlinked source file is still readable; it gets released upon close.

A relatively safe update sequence is: mkstemp/read+write/fsync/rename. The final rename is atomic, but that itself does not prevent races with multiple updaters (of course).


Comment on Re^3: read file line by line then do something and write to same file
Replies are listed 'Best First'.
Re^4: read file line by line then do something and write to same file
by davido (Archbishop) on Jun 16, 2014 at 19:44 UTC

    Yes, I believe you're correct regarding the strace. I recall now that the documentation is not 100% truthful as to what is happening behind the scenes. If you use -i.bak instead of -i, you'll probably see an open/rename/open/read+write/close/close instead of open/unlink...


    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2015-07-31 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls