如何在不等待Perl中换行的情况下立即打印文本? [英] How can I print text immediately without waiting for a newline in Perl?
本文介绍了如何在不等待Perl中换行的情况下立即打印文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在perl中有一个计算量大的任务,并且想通过打印出计算的每个部分完成之后的时间来通知用户该计算正在进行中.不幸的是,直到我打印出"\ n",我的句点都没有被打印出来.我该如何解决?
I have a computationally expensive task in perl, and would like to inform the user that computation is ongoing by printing out a period after each portion of the computation is completed. Unfortunately, until I print a "\n", none of my periods are printed. How can I address this?
推荐答案
您需要为STDOUT设置自动刷新.示例:
You need to set autoflush for STDOUT. Example:
use IO::Handle;
STDOUT->autoflush(1);
foreach (1..20) {
print '.';
sleep(1);
}
这篇关于如何在不等待Perl中换行的情况下立即打印文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文