Why use an empty print after enabling autoflush?
I've found something similar like this in a p开发者_如何学JAVAiece of code:
use IO::Handle;
autoflush STDOUT 1;
print '';
Is the purpose of "print" to empty a possibly filled buffer?
The print
forces all text in buffer (from previous prints) to be ouputted immediately. The code basically disable buffering and flush everything.
The print
call should be a wasted system call. perlvar
states, "If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel." The code in this example should turn on autoflush, causing a flush, then add noting to the STDOUT buffer and cause a flush. There may be another reason for the print but my guess is that the original author of the code made the same assumption as bvr that there would be data left in the buffer after the call to autoflush that would need to be flushed.
精彩评论