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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |