亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 在perl中打開文件進(jìn)行寫操作,是不是只有在關(guān)閉文件句柄后,才會把內(nèi)容寫入到文件中。 [打印本頁]

作者: ldorothy    時間: 2009-06-19 13:34
標(biāo)題: 在perl中打開文件進(jìn)行寫操作,是不是只有在關(guān)閉文件句柄后,才會把內(nèi)容寫入到文件中。
請教各位一個問題,在perl中打開文件進(jìn)行寫操作,是不是只有在關(guān)閉文件句柄后,才會把內(nèi)容寫入到文件中。
作者: yashiro_lj    時間: 2009-06-19 13:43
真正什么時候?qū)懀鶲S的讀寫策略有關(guān),一般OS會等buffer到了一定大小再一次性寫入,當(dāng)然你也可以aotuflush強(qiáng)制實(shí)時寫入

就這個問題來說,什么時候?qū)懳募完P(guān)閉文件句柄貌似沒有多大關(guān)系
作者: Perl_Er    時間: 2009-06-19 13:45
$|

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 for that. (Mnemonic: when you want your pipes to be piping hot.)
作者: ldorothy    時間: 2009-06-19 14:03
謝謝兩位,我先弄弄
作者: ldorothy    時間: 2009-06-19 15:54
用了$|,可是還不是我想要的結(jié)果。當(dāng)下面的程序在執(zhí)行中,被強(qiáng)制kill了,是否f.txt文件里什么內(nèi)容都沒有。
#!/usr/bin/perl -w
open HANDLE, ">>f.txt";
$num = 1;
$| = 1;
while ($num < 10)
{
        print HANDLE "($num)'s\n";
        $num++;
        sleep 1;
}
close HANDLE;
作者: Perl_Er    時間: 2009-06-19 16:06
use IO::File;

    $fh = new IO::File;
    if ($fh->open(">file.txt")) {
        print $fh "hello";
        $fh->autoflush(1);
        sleep 6;
        $fh->close;
    }
作者: yashiro_lj    時間: 2009-06-19 16:10
標(biāo)題: 回復(fù) #5 ldorothy 的帖子
把$| = 1改成select((select(HANDLE), $| = 1)[0])

或者use IO::Handle;再把$| = 1改成HANDLE->autoflush都可以實(shí)時寫文件
作者: Perl_Er    時間: 2009-06-19 16:13
http://perldoc.perl.org/functions/select.html
作者: ldorothy    時間: 2009-06-19 17:32
謝謝Perl_Er 和yashiro_lj 。
要多多努力學(xué)習(xí)了。謝謝前輩們




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2