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

How do true monks create hardcopy printouts of Perl code to share with their colleagues? We have some code review meetings & teaching sessions where it's easier to just give everyone a handout rather than trying to set up A/V or computers for everyone.

I can get some beautiful color syntax hilighting in vim and even export it to HTML, but printing HTML is always problematic.

I started to work with html2ps + ps2pdf, but before I go too far down this road, are there any tried & true methods for getting a nice printout of Perl code?

Replies are listed 'Best First'.
Re: hardcopy printout of perl code
by blue_cowdawg (Monsignor) on May 08, 2006 at 22:39 UTC
        How do true monks create hardcopy printouts of Perl code to share with their colleagues?

    If I want to make a hardcopy of my Perl scripts for any reason I tend to use:

    find . -name '*.p[lm]' -print | xargs enscript -G -Eperl
    from whatever top level directory the scripts live in. The enscript application does a nice job of syntax highligting and putting headings on output.

    Also from emacs there is a menu choice to print out the current buffer with syntax highlighting in color bseides.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: hardcopy printout of perl code
by bmann (Priest) on May 08, 2006 at 22:56 UTC
    I can get some beautiful color syntax hilighting in vim...

    Just :set popt=syntax:y and vim will print in color - if you have a color printer, of course. For more info, :help popt (short for printoptions) and :help popt-option. If you already have some options set you want to keep, set popt+=syntax:y will add the syntax option.

    Vim actually claims to print in color if it detects a color printer, but I've never seen it happen.

Re: hardcopy printout of perl code
by GrandFather (Saint) on May 08, 2006 at 22:11 UTC

    They don't. Depending on age they either use a USB flash drive, a stack of punched cards, or paper tape. Some monks use FTP or local area networks, others just wave at their monitor. :)


    DWIM is Perl's answer to Gödel
Re: hardcopy printout of perl code
by chargrill (Parson) on May 09, 2006 at 01:18 UTC

    perltidy has a nice -html option which spits out a syntax colored HTML version, which I suppose you could then go ahead and print.



    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
Re: hardcopy printout of perl code
by jdtoronto (Prior) on May 09, 2006 at 03:00 UTC
    I think the answer is that generally they don't. If someone wants to share Perl code with me then I expect to see it in a plain text file with a .pl extension. Why? Because we each have a favourite way of looking at code. We have colours that we prefer and we have apreentation style that we prefer and generally our own personal environment is set up to work that way. Within my IDE of choice (ActiveState Komodo as it happens) I have set up Perl Tidy to format things just the way I like it.

    If I want a hard copy, then I will print it the way _I_ like it.

    Besides, in the end any coder you send code to wants to set it up for his environment and run it himself. I know I do, so sending me code to look at in such a way that I cannot execute it simply guarantaees that it will hit the recycle bin even more quickly than it might otherwise.

    jdtoronto

Re: hardcopy printout of perl code
by TedPride (Priest) on May 09, 2006 at 01:03 UTC
    All my code is saved as text files, so I can just load and print in whatever text editor is handy. I don't bother with syntax highlighting. For that matter, I rarely give code printouts either - why would anyone want to bother with that when you can just load the code and test it? Anyone who can't understand what the code is doing as code isn't going to understand the printouts either.
Re: hardcopy printout of perl code
by hesco (Deacon) on May 09, 2006 at 06:22 UTC
    I don't print out much code. But when I would travel in the midst of developing some code I couldn't part with for a while, I have been known to use a2ps (anything to postscript). I'd have to review the man page again, but I would print out a module two columns to a page to good effect. It lost very little in translation and offered some suprisingly useful highlighting.

    The other day I read something here about editors for working in perl and based on a recommendation in that thread, installed and tried out scite. It provides menu options for exporting to html, rtf, pdf, latex and xml. I'm curious to see the LaTeX. And I tried the pdf and it looks good. If I have X available and am not limited to cli tools, it has likely just become my preferred tool for this task.

    -- Hugh

    if( $lal && $lol ) { $life++; }
Re: hardcopy printout of perl code
by zentara (Archbishop) on May 09, 2006 at 16:09 UTC
    I'll just mention this one I use
    a2ps -P display --pretty-print=perl --prolog=color script.pl
    that will open gv and show you a preview, then you can change "-P display" to "-P lp1" (or whatever you want)

    That will print 2 pages per sheet in landscape mode, which is handy for seeing more code per sheet. -2r is the default, which is 2 pages-landscape. -R1 will give the normal 1 page portrait layout.


    I'm not really a human, but I play one on earth. flash japh
      Nice suggestion. This was looking real good till it hit a regex delimited by ! and split up on multiple line with /x. Then it lost the syntax. Or maybe it was that the regex ended in a single quote... I'm actually starting to believe that nothing can parse perl except perl.
Re: hardcopy printout of perl code
by blazar (Canon) on May 09, 2006 at 12:08 UTC

    I don't print out hardcopies. But if I had to, then I'd use LaTeX with the listings package. I tried it once and even though nothing but perl can parse Perl, I could verify that it does an excellent job of syntax highlighting the code, provided it's not obfu, you know!

      Looks like a great system. I love TeX. No color out of the box though.

        Color enough courtesy of suitable packages (even core ones). See e.g. my talk at http://mosquito.scumm.it/~blazar/laurea/, certainly not the best example around - just the first that occurred to me. And I'm sure about the location! ;-)

Re: hardcopy printout of perl code
by parv (Vicar) on May 10, 2006 at 02:10 UTC
    If it is pure code -- no English text or pictures|graphics -- i use "enscript(1)", otherwise "LaTeX" with "listings" package.
Re: hardcopy printout of perl code
by spiritway (Vicar) on May 09, 2006 at 11:02 UTC

    I can't add to the excellent suggestions already mentioned. But I am curious - why hard copy? Why not e-mail them the *.pl file (or *.pm, or whatever), or put it on a disk? It seems that printing it to hard copy renders it far less useful, than keeping it in a format that can easily be copied and transmitted, formatted according to each recipient's taste, and so on...

      This is for meetings & teaching sessions where we have nothing but a room available, no A/V, no computers.
Re: hardcopy printout of perl code
by swampyankee (Parson) on May 09, 2006 at 14:37 UTC

    Printouts to share code? How, well, passé.

    Sharing code? Posting it here (if I ever generate any code which deserves that fate), or via email, my employer's network, or flash drives.

    I do print code when I am going to modify it, but (at work), I've no access to a color printer, so I just print it in a fixed pitch font (like courier), in landscape mode.

    emc

    "Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
    —G. Steele