如何在变量中捕获Perl的STDOUT? [英] How do I capture Perl's STDOUT in a variable?

查看:196
本文介绍了如何在变量中捕获Perl的STDOUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用一个使用print写入STDOUT的函数.如何在变量中捕获它?

I am calling a function that writes to STDOUT using print. How can I capture this in a variable?

请注意,所有这些操作都在同一过程中发生.

Note that all this happens within the same process.

推荐答案

处理此问题的新方法是使用捕获::小.您可以通过外科手术使用它来影响您需要的程序部分,而不会打扰其他任何事情.但是,我可能会执行 cjm建议,因为它不需要模块.

The new, cool way to handle this is with Capture::Tiny. You can use it surgically to affect just the part of the program where you need it without disturbing anything else. But, I'd probably do what cjm recommends since that doesn't require a module.

这篇关于如何在变量中捕获Perl的STDOUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆