问题
I've found something similar like this in a piece of code:
use IO::Handle;
autoflush STDOUT 1;
print '';
Is the purpose of "print" to empty a possibly filled buffer?
回答1:
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.
回答2:
The print
forces all text in buffer (from previous prints) to be ouputted immediately. The code basically disable buffering and flush everything.
来源:https://stackoverflow.com/questions/5014750/why-use-an-empty-print-after-enabling-autoflush