This is a trivially simple little formatting trick I use when tossing in lines to dump out during debugging or whatnot.
My thought process tends to go along the lines of, "Hey, I need to check the values of this variable here, so I'll add a print statement...wait, I should print out another one. Wait, I really need to print out this whole complex data structure, I need to dump it."
Nothing special there, just use Data::Dumper and print it out. But I find that marginally annoying since (1) if I later want to shut off that print line and remove the module, I need to add two comments or (2) if I want to delete the statement, I need to remember to delete two lines, lest I end up with useless imports of Data::Dumper.
Solution? Simply toss the use onto the end of your debugging line. Since the use is hit at compile time, you're still importing the module in advance, so it works. Your print line is very clear on the left side of your code (no use in front of it), and then you only have one line to go back and clean up when you get rid of it.
print Dumper($some_complex_structure); use Data::Dumper;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: More clear dumper debugging lines
by merlyn (Sage) on Jul 13, 2006 at 14:58 UTC | |
by Aristotle (Chancellor) on Jul 16, 2006 at 10:51 UTC | |
|
Re: More clear dumper debugging lines
by Aristotle (Chancellor) on Jul 16, 2006 at 10:55 UTC |