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;

In reply to More clear dumper debugging lines by jimt

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.