多谢。 http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?--Why-must-I-do-this 上面讲得很清楚。 总结下,如果不是每次print后都要flush,可以使用 use IO::Handle <http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?--Why-must-I-do-this> 在要写入时候 FILEHANDLE->flush <http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?--Why-must-I-do-this>
<http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?--Why-must-I-do-this> 2009/8/12 Yuan Jiang <[email protected]> > 嗯嗯,是这样的。 > > 哈哈,我不太会perl, 当初google到这句 > > or using the traditional idiom: > > select((select(OUTPUT_HANDLE), $| = 1)[0]); > > 就经常把它在代码里粘来贴去滴...... > > 2009/8/11 Qiang (James) <[email protected]> > >> yi wang wrote: >> > 程序用追加模式打开一个监控文件,写入一行信息,然后进入一个大循环,在循环 >> > 里面没迭代一次写一次文件,最后程序结束前关闭文件。 >> > 由于缓存机制,并不能在程序运行时及时看到写入文件的内容,如何才能不靠关闭 >> > 文件,强制将缓存写入文件呢? >> > >> >> 短答案:使用 Perl 的 autoflush 符号 $|, 通过 $|++ (或者 $|=1) 设为true 即可. >> >> 更长点的解释请阅读 >> >> http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?--Why-must-I-do-this >> ? >> >> Qiang >> >> >> > > > -- > 姜源 > Yuan Jiang > http://blog.vetcafe.net > http://twitter.com/sleetdrop > > > > > -- 和你在一起 --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
