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.

Why? and is there a way around this? I would like to know what is happening while it is happening, and not after it is finished.

Your output is being buffered. 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, but the easiest thing is to enable autoflushing which will do that implicitly. Just add

  use IO::Handle;
  STDOUT->autoflush;

to the start of your program.

You should also take a look at the File::Copy module for a way to perform the copy without shelling out to a separate utility.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to