I have a library of modules I'm trying to debug, and I'd like to instrument some or all of them to output line numbers to STDERR, to help trace execution through some non-linear code, filled with lots of callbacks and such, where the normal code emitting quite a lot to STDOUT and STDERR.

Currently, I do a manual find/replace in the editor of big chunks of code, equivalent to this:

s/;\s*$/; $DEBUG and printf STDERR "***LINE*** [%s] %s: %s (%d)\n", ti +me_stamp(), __FILE__, __PACKAGE__, __LINE__;/

This of course makes the code hard to read, and doesn't work everywhere (I think use and package might have problems with this, maybe others.) Colleagues often get distracted with these, instead of seeing the important bits.

Really I'd just like a source filter or module I can invoke on the command line to safely do this between statements, and not muddy up the source code.

Any suggestions?

Update: I use a special script to run the script on a remote cluster of hardware that is not available locally. All files needed are copied over and untarred into an appropriate temp dir, the script run, and all STDOUT and STDERR reported back to the originating terminal.

Interactive debug would be my first choice, but the nature of the system makes it much easier to do s/// and print lines into the output logs.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Module for Printing Line Numbers in Debug? by QM

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.