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 print
and the more recent https://stackoverflow.com/questions/387702/how-can-i-hook-into-perls-print/6281636However, I wonder if there are any recent developments since then or a definite HOWTO.
thanks, bliako
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Override printing to STDOUT/ERR
by Corion (Patriarch) on Apr 13, 2018 at 13:10 UTC | |
by bliako (Monsignor) on Apr 13, 2018 at 13:56 UTC | |
Re: Override printing to STDOUT/ERR
by LanX (Saint) on Apr 13, 2018 at 13:57 UTC | |
by bliako (Monsignor) on Apr 13, 2018 at 14:04 UTC | |
by learnedbyerror (Monk) on Apr 15, 2018 at 18:36 UTC | |
by bliako (Monsignor) on Apr 17, 2018 at 10:00 UTC | |
Re: Override printing to STDOUT/ERR
by Tux (Canon) on Apr 17, 2018 at 10:10 UTC | |
by perlancar (Hermit) on Dec 20, 2018 at 15:34 UTC | |
Re: Override printing to STDOUT/ERR
by LanX (Saint) on Apr 13, 2018 at 13:30 UTC | |
by bliako (Monsignor) on Apr 13, 2018 at 13:58 UTC |