Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Override printing to STDOUT/ERR

by Tux (Abbot)
on Apr 17, 2018 at 10:10 UTC ( #1213050=note: print w/replies, xml ) Need Help??


in reply to Override printing to STDOUT/ERR

Maybe Capture::Tiny serves your purpose enough:

$ perl -MCapture::Tiny=capture -wE'my($out,$err,$exit)=capture{say"Hel +lo";warn"Die\n";};say"OUT:$out";say"ERR:$err";say"EXIT:$exit";' OUT:Hello ERR:Die EXIT:1

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Override printing to STDOUT/ERR
by perlancar (Friar) on Dec 20, 2018 at 15:34 UTC
    While Capture::Tiny is simpler, the OP wanted to separate output according to the package/file the print() originates. So in this case, a tie-based solution like Tie::STDOUT is more appropriate as it lets you call your custom code on every print() or printf() or syswrite(), and then you can use caller() to extract the source location of each print() and act accordingly.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1213050]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2020-10-25 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?