in reply to How to Print All Variables in a Script
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.
|
|---|