You might try this:

First, you can list all of the variables and subs in use in the script by executing the following command:

perl -MO=Xref myscript.pl >myscript.xref

That will dump all kinds of good information into 'myscript.xref'.

Armed with that info, you can pick and choose which variables you want to track. From that point, have a look at my node: "Scalars tied to logfiles" to see one way of logging scalar access via Perl's tie interface. This solution would have to be adapted and reworked a bit if you wanted to also log hashes and arrays.

Another alternative is that there's probably an easier way with something in the Devel namespace.

Update: Thanks for the "lazy link alert". I was in a rush this morning when I posted it, and didn't have a chance to check. I've fixed it now.

Update2: One module to look at might be Devel::FindGlobals. It appears that if you provide it with a hash of lexical names, it will look at them too. Not sure it will give you as much info as you want or not, but it might be a start.


Dave


In reply to Re: How to track variable usage in a script? by davido
in thread How to track variable usage in a script? by Scarborough

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.