How do I capture Perl's STDOUT in a variable?

前端 未结 2 1980
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 14:47

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.

2条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 15:32

    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.

提交回复
热议问题