Perl运算符:$| ;美元符号加上加号

前端之家收集整理的这篇文章主要介绍了Perl运算符:$| ;美元符号加上加号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个已经发布的perl代码的新版本,并找到了一行:
$|++;

AFAIK,$|与管道有关,如in this link所述,我明白这一点,但我不知道(plus plus)是什么意思.

先谢谢你.

编辑:找到答案in this link

简而言之:它强制在下一个语句之前打印(刷新)到控制台,以防脚本太快.

Sometimes,if you put a print statement inside of a loop that runs really really quickly,you won’t see the output of your print statement until the program terminates. sometimes,you don’t even see the output at all. the solution to this problem is to “flush” the output buffer after each print statement; this can be performed in perl with the following command:

$|++;

[update]
as has been pointed out by r. schwartz,i’ve misspoken; the above command causes print to flush the buffer preceding the next output.

解决方法

$|默认为0;做$|因此将其增加到1.将其设置为非零可以启用当前选择的文件句柄的自动刷新,默认情况下为STDOUT,并且很少更改.

所以效果是确保print语句等立即输出.如果要输出套接字等,这是有用的.

猜你在找的Perl相关文章