聘我网

新概念招聘3.0

如何将输出到STDOUT的内容保存到变量中?

vote up0vote downstar

求样例啊求样例

 

1 个答复

vote up0vote downcheck
my $stdout;
{
    local *STDOUT;
    open STDOUT,'>:scalar', \$stdout;
    print 'hello world';
};
print "content of stdout is " . $stdout . "\n";

输出:

content of stdout is hello world
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.