Chinaunix

标题: 关于换行 [打印本页]

作者: wutuobangduan    时间: 2014-02-24 08:54
标题: 关于换行


只有\n和\en不同,使用\n时每隔一秒输出,而且结果换行了,使用\en时,不仅没有换行,而且是隔了10秒后,所有结果一起输出。
新手求解疑。
作者: yestreenstars    时间: 2014-02-24 09:20
我在我这里测试,两个都是10s后才输出,一个有换行,一个没有~
作者: wutuobangduan    时间: 2014-02-24 09:24
回复 2# yestreenstars



   
作者: jason680    时间: 2014-02-24 10:25
回复 1#wutuobangduan

easy solution:
$| = 1;

-----------------------------------

http://blog.csdn.net/BeTalker/article/details/8362730
...
在背后捣鬼的就是IO 缓冲。默认情况下,Perl的STDOUT是有缓冲的
...

-----------------------------------

$ perldoc perlvar
NAME
    perlvar - Perl predefined variables
    ...

    HANDLE->autoflush( EXPR )
    $OUTPUT_AUTOFLUSH
    $|      If set to nonzero, forces a flush right away and after every write
            or print on the currently selected output channel. Default is 0
            (regardless of whether the channel is really buffered by the
            system or not; $| tells you only whether you've asked Perl
            explicitly to flush after each write). STDOUT will typically be
            line buffered if output is to the terminal and block buffered
            otherwise. Setting this variable is useful primarily when you are
            outputting to a pipe or socket, such as when you are running a
            Perl program under rsh and want to see the output as it's
            happening. This has no effect on input buffering. See "getc" in
            perlfunc for that. See "select" in perlfunc on how to select the
            output channel. See also IO::Handle.

            Mnemonic: when you want your pipes to be piping hot.

作者: wutuobangduan    时间: 2014-02-24 10:35
回复 4# jason680


    非常感谢,很详细。
作者: pitonas    时间: 2014-02-24 13:49
{:2_172:}  啊!! 好厉害!!感激!!
jason680 发表于 2014-02-24 03:25
回复 1#wutuobangduan

easy solution:
$| = 1;





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2