Why use an empty print after enabling autoflush?

只愿长相守 提交于 2020-01-04 01:56:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!