He said he wants a Perl code pretty-printer. There was one submitted as a paper to the Perl Conference a year or two ago, but it never was released as a final product.

Update: Apache::PrettyPerl is a mod_perl module to turn Perl code into syntax-highlighted HTML on the fly. It might be worth a look, too.

I've seen hacks that use the C formatter indent, but nothing's done a great job with it. The problem is that Perl is so bloody flexible, it's possible to write code that doesn't look like code to most pretty-printers.

The a2ps program claims to handle Perl, but I don't know how well.

There are two in-Perl solutions. The first is the B::DeParse module, which takes the compiled form of your program and spits it back out as Perl code. This takes some guesswork, though, as your program is seen after Perl has optimized it. The module is still under development, so feel free to fix any bugs you find :-)

The second solution is to write your own. Good luck! A good place to start might be the Text::Balanced module. It's not as heavyweight as Parse::RecDescent. Perl is a complicated beast, but you might be able to do rudimentary parsing using either module.

Let us know how the search goes. I'm sure many others would like a Perl pretty-printer.


In reply to RE: Re: Parsing Perl in Perl by gnat
in thread Parsing Perl in Perl by awwaiid

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.