|No such thing as a small change|
Waiting for a file to be writtenby why_bird (Pilgrim)
|on Oct 14, 2008 at 13:02 UTC||Need Help??|
why_bird has asked for the wisdom of the Perl Monks concerning the following question:
I have a perl script that is (re-)writing a file using Tie::File, then calling a process to run in the background with this file as the input. I do this in a loop, so that I get a different version of the file for each runthrough of the process.
The problem is (I think..) that the file has not always finished writing by the time I call the next process. How do I wait for a file to finish writing before calling my process? I do not think I am suffering from buffering. I have $|=1. Do I maybe need to somehow set this for the individual file instead?
Perhaps I have got completely the wrong end of the stick and I have another problem here.. if so, does anyone have any suggestions?
This code should illustrate my problem:
On my system, this gives the output:
Which is the same type of problem as I get with my proper script. Hope this demonstrates what I mean.
update: I realise I've asked a similar question before (albeit in a more rambling fashion). I thought untie(@array) would have the same effect as close(FILEHANDLE), but it doesn't seem to. Making sure I'd close'd my file before did the trick, but untie-ing doesn't seem to have the same effect.
update 2: Actually, as Moritz pointed out, the file is being written too early, not too late.. d'oh
Those are my principles. If you don't like them I have others.
-- Groucho Marx