我有以下PHP代码,它打开输出缓冲区,包含一个文件,将其存储在一个变量中,并清除缓冲区:
ob_start();
include('test.html');
$input=ob_get_clean();
等效项在Perl中会是什么样子?
发布于 2013-01-22 13:00:14
特殊变量$|
。当设置为非零时,在每次写入或打印后执行缓冲区刷新
发布于 2013-01-22 13:19:28
$| = 1;
将为当前选定的控制柄(默认情况下为STDOUT
)启用禁用缓冲。换句话说,
$| = 1;
在功能上等同于
use IO::Handle qw( ); # Not needed since 5.14.
select()->autoflush(1);
这通常意味着
use IO::Handle qw( ); # Not needed since 5.14.
STDOUT->autoflush(1);
发布于 2014-07-10 02:52:45
因此,等价的方法是:
# open a file handle try to get test.html
open(my $fh, "<", "test.html") ||
die 'Could not open test.html: '.$!;
# return the currently selected filehandle
select($fh);
#clear the output buffer
select()->autoflush(1);
参考
https://stackoverflow.com/questions/14451820
复制相似问题