So, that at the end of the script, I can just run something like print_all_variables, and it will print the contents of all variables...

Stating the goal that way only makes sense if all the variables are global in scope. And if that's true, it's hard to say whether just printing out all their values at the end is going to be much help as a debugging strategy.

In general, it is considered better practice for relatively few variables to have global scope (apart from the ones defined by perl itself, such as ($_, $/, $\, $|, $!, $@, @INC, ...) which is a pretty long list by itself).

And when you try to maximize the use of limited lexical scope for your own variables (which is a Good Thing™), it means many of them are not available for inspection when the script reaches its last statement before ending (they've gone out of scope, and no longer exist).

If you're trying to debug or comprehend some spaghetti code, I don't think there is any substitute for focused, step-wise diagnosis. If it's producing bad output or you just want to know how a certain output came to be, trace back from the point where that output is printed, use 'perl -d' to run the script so you can set breakpoints, etc.


In reply to Re: How to Print All Variables in a Script by graff
in thread How to Print All Variables in a Script by bichonfrise74

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.