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/6281636

However, I wonder if there are any recent developments since then or a definite HOWTO.

thanks, bliako


In reply to Override printing to STDOUT/ERR by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.