Hmm.. why use a hash for keys that are just consecutive integers starting at 0? And why write to a temporary file if you can feed the external process directly? Also, Perl knows lists; use the easier to maintain for(@LIST) form of for loops when you don't have special requirements. As well, post-increments return the value a variable had before incrementing it, so you don't need to do that in two steps. Finally, your wrap-around code can be expressed much more naturally using a modulo operation.

use strict; use warnings; my @COLOR = ( "0 0 0", "0 0 1", "0 1 0", "0 1 1", "1 0 0", "1 0 1", "1 1 0", "1 1 1", ); my $postscript = << 'END_POSTSCRIPT'; %! 72 72 scale .25 .25 translate /Courier findfont .095 scalefont setfont END_POSTSCRIPT my $sy1 = 1; my $color = 0; for my $y (1 .. 148) { my $sy = $sy1; $sy1 %= 10; for my $x (1 .. 130) { my $_x = $x * .060; my $_y = $y * .070; $postscript .= "$COLOR{$color} setrgbcolor\n"; $postscript .= "$_x $_y moveto ($sy) show\n"; $sy = ($sy + 1) % 10; $color = ($color + 1) % 8; } } open '|-', my $lp, 'lp' or die "Couldn't spawn lp: $!\n"; print $lp $postscript;

Please use strict and warnings, until you know when you don't need to. This is not just advice to appease the theorists in the ivory tower - making your code work with them will save you many a headache. See

  • Use strict warnings and diagnostics or die
  • Use strict warnings and diagnostics
  • Use strict and warnings
  • Makeshifts last the longest.


    In reply to Re^5: send color text to printer by Aristotle
    in thread send color text to printer by jhasting

    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.