in reply to Re^2: Strange problem trying to clean garbage from start of mailbox file
in thread Strange problem trying to clean garbage from start of mailbox file
If there was only one process involved, the outcome would be quite predictable. However, since you constructed a pipeline of two processes there is a chance that the first one wins the race and catches a portion of the file before the file is destroyed by the second one. However, as you already observed, you can not rely on that.
To solve that problem you can use a temporary file (like perl -i does behind the scene) or read and write to the file through a single file handle in a single process, which may prove somewhat more difficult to get right.
If you are interested anyway you may want to look up file access modes in perlopentut, specifically +<. You also might find the truncate function useful. The Perl Cookbook has excellent explanations of the different techniques.
|
|---|