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

Fellow Monktacular Monks, I have a problem. I need to print out a large ammount of source code that is easy reading.

While I've already taken the apropriate measures to ensure code readability, something tells me that I can't simply:
cat *.pl | lpr.

So what I'm looking for is something or some way to generate nice, possibly syntax highlit documents with a header that has the filename and page number and line numberings. Should that fail I'll write some sort of LaTeX generator in perl to do what I need and post it here, but I don't want to re-invent the wheel.

(As an aside, that comment may doom me just because the monks with the answer may withold it to see what I do)

Update: After a quick super search I found this node about the exact same thing, but found the options only so-so. I'm hoping that in almost a year things have changed.

Replies are listed 'Best First'.
Re: Formatting Perl for Printing
by derby (Abbot) on Feb 12, 2007 at 23:32 UTC

      Enscript gets my vote too. I have used enscript to prettyprint source code and it does a good job.

      Mahesh

Re: Formatting Perl for Printing
by Joost (Canon) on Feb 12, 2007 at 23:39 UTC
Re: Formatting Perl for Printing
by renodino (Curate) on Feb 13, 2007 at 02:32 UTC
    If you want fancy syntax hilighting, you might just use PPI::HTML and then print from your favorite web browser (most of which will automatically add appropriate headers/footers). And if you want to morph the code a bit before printing, PPI::HTML makes it pretty easy to just regex for spans.

    If you really feel the need to get crazy with reformatting, you could use PPI to generate XML, then apply XSLT or somesuch.


    Perl Contrarian & SQL fanboy
Re: Formatting Perl for Printing
by swampyankee (Parson) on Feb 13, 2007 at 04:33 UTC

    Vim has a syntax highlighting mode for Perl, and an associated filter to convert highlighted Perl to HTML. The cperl mode for emacs or xemacs has a filter to convert its highlighted Perl to postscript.

    And perltidy is a useful code beautifier.

    emc

    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center
Re: Formatting Perl for Printing
by shmem (Chancellor) on Feb 13, 2007 at 00:09 UTC
    but I don't want to re-invent the wheel.

    While hearing Bach's inspired music, I am re-inventing it. The music unfolds in my conciousness, which is where I am. And I could not point out His points any better.

    Sometimes I sit around and meditate about wheel inventing: imagining how the woman felt that actually invented the wheel, and I am trying to get at that all-caps HEY! THATS IT! feeling re-creating her creation.

    Then sometimes the wheel's just broken. Well I fix it, to no avail. I don't re-invent it (because the idea is there), but do somehow, made of rags, and suddenly it's not only a wheel but one that sings "Amazing Grace" while rolling.

    So, please keep re-inventing wheels. Wheels would be so boring but for those that dare to re-invent them...

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Formatting Perl for Printing
by perrin (Chancellor) on Feb 13, 2007 at 01:46 UTC
    I see that someone else has suggested perltidy --html. What did you not like about that option? It looks great to me.
Re: Formatting Perl for Printing
by zentara (Cardinal) on Feb 13, 2007 at 12:09 UTC
    # will open it in gv for preview a2ps -P display --pretty-print=perl --prolog=color script.pl # select printer option -P lp1 # is the print syntax # how many pages per sheet -2r = default -R = portrait -r = landscape -R1 = single page per sheet

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Formatting Perl for Printing
by klekker (Pilgrim) on Feb 13, 2007 at 10:44 UTC
    The Node hardcopy printout of perl code in your 'update' contains the solution I use for myself: blazar mentioned the LaTeX package 'listings'.

    Here is a very basic example:
    \documentclass {article} \usepackage{listings} \usepackage{color} \lstset{language=Perl} \begin {document} \begin{lstlisting}[frame=trbl]{} #! /usr/bin/perl use strict; use warnings; print "Intentionally left blank..."; \end{lstlisting} or \lstinputlisting{your_perl_file_here.pl} \end {document}


    But check the documentation (pdf): http://tug.ctan.org/tex-archive/macros/latex/contrib/listings/listings-1.3.pdf.
    There are many possible configurations: line numbers, highlighting (for perl: print or ignore pod) etc.

    It should not be necessary to write a LaTeX generator and I for myself found this solution (although more than a year old) better than so-so :)

    k