(Update: scratch the idea of changing the behaviour of code tags - see jdporter's reply and yes Perl::Tidy would make more sense than from scratch, see Derby's reply).

Re-reading the various nodes relating to editing and moderation, I couldn't find a clear statement as to whether editing should go as far as cleaning up untidy code, except that it is standard enough to request the addition of code tags via the moderation tool.

Every now and again someone complains that a post has untidy code in it, especially, inconsistent indentation that makes it hard for the reader to match block and other boundaries.

It appears reasonable to nudge the author into cleaning up his own code. On the other hand, it occurred to me that not everyione is aware of perltidy which does it automatically in a flash. And the whole point of requesting editing via moderation is to allow inexperienced, potentially novice, posters to make themselves heard without having to run a technical/site-"in"-group gauntlet first.

I did a quick straw poll through the SOPW and nearly half of the posts look up to perltidy standards. The other half and a bit apparently weren't, although with widely varying degrees of deviancy from the very trivial to the profoundly perverted (...UK readers can calm down now; I am only talking about coding standards ;) ).

Now, I have no idea what precise facilities janitors have at their disposal, nor any insight into how PM is devved, but it occurred to me that it might not be that hard to automate perltidy for select and press-button use by janitors or even to have specific perltidy tags available or another option might be to enhance the code tag to automatically feed the code through perltidy and replace the code with the results, (e.g. something like the code below).

The actual question I am raising is - should perltidy be automated here for these purposes, and if so, should it be automatically for every code-tagged block (update: to clarify: I meant to imply the alternative option to that as being a separate tidying tag for optional use only) or something requested by moderators and performed by janitors? Or the status quo is "advise but not enforce perltidy". I'll say this much about the status quo option: if the more fastidious monk wanted to goad OPers into tidying code themselves, they would have to engage in it on a more than full-time basis, given the steady flow of "unperltidy" postings!

sub Tidy { my ( $text, $cmdopt ) = @_; my $tmpfile = "/tmp/Tidy.$$." . join( '', localtime()) ."tmp"; open my $th, ">$tmpfile" or die; print $th $text or die; close $th or die; my $pid = open my $ph, "perltidy -st $cmdopt $tmpfile |" or die; my $tidied = join '', <$ph>; close $ph or die; waitpid $pid, 0; unlink $tmpfile; return $tidied; }
__________________________________________________________________________________

^M Free your mind!


In reply to Automate perltidy for PM code? by Moron

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.