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

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

问题描述

我正在调用一个使用打印写入 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天全站免登陆