buppy has asked for the wisdom of the Perl Monks concerning the following question:

Has anybody written any perl code formatters (written in perl of course)that conform to the perldoc document perlstyle? If so where can I find it?

Replies are listed 'Best First'.
Re: Perl code formatter?
by atcroft (Abbot) on Nov 12, 2002 at 05:53 UTC
      PerlTidy is the bomb!

      I looked for perl beautifiers five years ago and there was nothing. I'd heard of perltidy and a few other attempts through the years, but I'd heard "perl is too hard to parse" so many times I didn't believe any of them would do any good. But perltidy rocks.

      I've taken a number of pieces of nasty code that I've been given to maintain and stuffed them through perltidy so I could get to doing real work fast instead of spending my life doing massive reformatting just so I could figure the code out. PerlTidy really does what you'd hope for with a zillion different options depending on your taste (or lack thereof). But where I was really shocked and amazed was the HTMLification feature. This lets you colorize your perl code similar to the way gvim does. I've been able to use the colorized perl code as part of code analysis work. It makes a much nicer product that I was ever able to achieve with enscript.

      atcroft, chicks, Louis_Wu... perltidy rocks! thanks a bunch. Now I can take all that code written by the last contractor and make sense of it.
Re: Perl code formatter?
by Louis_Wu (Chaplain) on Nov 12, 2002 at 05:55 UTC
Re: Perl code formatter?
by nothingmuch (Priest) on Nov 12, 2002 at 09:28 UTC
    The core module B::Deparse may also be of use. It uses compiled code and turns it into formatted code, pretty neatly. I don't know about perlstyle conformance, but it certainly seems that way.

    The difference between it and perltidy is that B::Deparse doesn't know what you've written, but just what is to be executed, based on what you have written. Thus, it skips comments, and it may output "modified" code, as the internal representation may differ from your own code (many processing steps are taken, such as optimisation...).

    Perhaps more interesting than useful, but still worth a mention.

    -nuffin
    zz zZ Z Z #!perl
Re: Perl code formatter?
by Jaap (Curate) on Nov 12, 2002 at 14:36 UTC
    There is also the Beautifier module. As far as it's posible, it conforms to perlstyle.

    If you have any questions about beautifer, feel free to mail me.
      It's nice, except that the default mode does not conform to PerlStyle with regard to the placement of the opening braces :-{
      Otherwise it seems to do a reasonably good job.