Is there a way to capture a subroutine's print output to a variable so I can send it to stderr instead?

后端 未结 4 1022
离开以前
离开以前 2021-01-12 08:50

Suppose we have:

sub test {
        print \"testing\\n\";
}

If there is a case where I want to have it print to stderr instead of stdout, i

4条回答
  •  有刺的猬
    2021-01-12 09:12

    This work for me

    local *STDOUT;
    open(STDOUT, ">", \$Result);
    &test();
    print $Result;
    

提交回复
热议问题