A long time ago, in a node far, far away, a fellow Monk pointed me at the Perlish Coding Style. For those not familiar, the PCS is all about having a left column that clearly indicates program structure. To shamelessly steal the first example from the site above:

; sub capture (&;*) { my $code = shift ; my $fh = shift || select ; local $output ; no strict 'refs' ; if ( my $to = tied *$fh ) { my $tc = ref $to ; bless $to, __PACKAGE__ ; &{$code}() ; bless $to, $tc } else { tie *$fh , __PACKAGE__ ; &{$code}() ; untie *$fh } ; \$output }

Certain things about this appeal to me, but I can't help thinking "I'd never use this for published code", and the proponent of this style agrees with me. However, I have found one piece -- the idea of the semicolon as a separator rather than a terminator -- to be useful when debugging.

Essentially, I use the leading-punctuation style encouraged in PCS to mark code that's inserted for debugging purposes:

use strict; use warnings; use XML::Simple; ; use Data::Dumper::Simple; my $struct = XMLin('test.xml'); ; print Dumper($struct); if (defined $struct) { my $result_set = process_data($struct); ; print Dumper($result_set); send($result_set); } #...

Note how debugging lines stand out, but no change to indenting is required. Of course, you'll note that instead of putting the semicolon only in front like PCS, I "sandwich" the statements -- this is necessary, and is in fact easier since I'm used to ending lines with semicolons anyhow.

The additional advantage to this is that debugging statements can be programatically filtered out:

perl -ne 'next if m{^\s*;\s*[^#]}; print $_' debugging.pl > stripped.p +l

Of course, one has to be a little more careful about heredocs:

print <<HEREDOC Some lines go here HEREDOC ; #this would be filtered out if I didn't leave a comment

Thoughts?

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Perlish Debugging Style by radiantmatrix

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.