|The stupid question is the question not asked|
Override printing to STDOUT/ERRby bliako (Chaplain)
|on Apr 13, 2018 at 12:53 UTC||Need Help??|
bliako has asked for the
wisdom of the Perl Monks concerning the following question:
Hello wise Monks,
I would like to override Perl's printing to STDOUT/STDERR with my own version which simply adds the line number the print function call happened. Ideally, ALL the line numbers/filenames/packagenames in the case of nested calls all the way to the top/main because I want to separate a program's STDOUT depending on which part of the program it originated.
You can assume I have complete control over the source code (of the program which I want to override its print statements) and can change anything I like. HOWEVER, I do not have control of the source-code of the many packages the program may be using and the print statements therein.
Initially I thought to just replace print with my_own_print in the source code and run that. Then I realised that it should only affect print in a function-call context and I used PPI for this purpose. And then I realised that there are other ways of printing to STDOUT/STDERR including the croaks etc. And finally I also realised that print statements in the packages will be out of my control. So this plan collapsed fairly quickly.
Now, I have already read the thread !Overriding Builtin printand the more recent https://stackoverflow.com/questions/387702/how-can-i-hook-into-perls-print/6281636
However, I wonder if there are any recent developments since then or a definite HOWTO.