Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
(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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found