On 02/17/2008 03:48:40 PM, Rob Dixon wrote:
MK wrote:
>
I have a subroutine that begins with a message ("Processing...") and
then
proceeds to perform several gigs worth of file transfer via system
calls.
Basically:
sub transfer {
print "Processing...\n";
foreach $e (@array) {
print "file $e\n";
system "cp $e"; #or whatever
}
print "...done\n";
}
Unfortunately, perl completes the entire (minutes long) routine
BEFORE it
prints anything, so when the whole thing is done, suddenly the
"Processing...file X...file Y...file Z...done" appears.
Your output is being buffered.
Yes. This is clearly the problem, thanks. As for the solution, I'm
afraid i
still need help.
A specific complication may be that there is a write to then a read
from a
text file list of the files to copy, so actually (with recommended
buffering
commands and use File::Copy):
sub transfer {
STDOUT->autoflush(1);
print "Processing...\n";
open(FH, ">list.txt"); FH->autoflush(1);
print FH "data";
close(FH);
open(ALT, "<list.txt"); ALT->autoflush(1);
while (<ALT>) {
foreach $e (@array) {
chomp $_; ALT->flush();
copy("$_","fileX");
[a tk command like print "...file"]
}
[a tk command like print "...done"];
}
None of this made any difference. None of the FAQ's i found refer to
the copy
or system "cp" as an issue (neither do they say it is not). Probably i
can do
this with arrays to avoid the list.txt, but i would prefer the actual
log as
well anyway. Could this be a tk issue (i have yet to try it as a plain
script)?
The buffer is flushed only either when it
is filled up or when the filehandle is closed (when the program
terminates). You could flush the buffer explicitly after each print
statement
i believe that is ALT->flush(). Is there a possible filehandle for the
actual
binary in the copy statement that could be set to autoflush, other than
STDOUT? The files are not concatenated.
but the easiest thing is to enable autoflushing which will do
that implicitly. Just add
use IO::Handle;
STDOUT->autoflush;
yep. did that too.
There must be a way out of this.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/