In a message dated Sat, 8 Feb 2003, Tom McDonough writes: > I've used perl on my mac os X.2 for use on the terminal and cgi scripts on a > website but I've never printed to the printer directly from a perl program. > > I know I have to open a filehandle but I don't know the filehandle name to > use - or where to find that name. I have a Canon i550 printer. The > contents of /private/etc/printcap is 'i550:'.
Assuming you're printing using Unix services, there's more than one way to do it (these all assume a working "lpr" command, which will only be true in Jaguar 10.2): 1) Write to a file, then run "lpr <filename>", i.e. # stuff that writes to $file system "lpr $file"; 2) Open lpr on a filehandle and print to it: open LPR, "|/usr/bin/lpr" or die "Can't open /usr/bin/lpr: $!\n"; foreach my $line (@data) { print LPR $line; # buffer a line for later printing } close LPR; # printing happens at this point In both cases, this will work for either plain text with embedded newlines or with PostScript. If it's plain text, you must ensure that you send newlines at appropriate intervals--lpr will not reliably wrap. You will get simple monospaced output, either 12pt Courier or 12pt Monaco depending on the printer. However, if you're sending PostScript, you need to be sure that you do not precede the PostScript preamble with any other text, or else you will print the PostScript code as text--and even a simple PS document will take many, many dozens of pages to print as code. Not what you want. Formatting your text into nicely-printing PostScript is definitely beyond the scope of this list. Take a look at the PostScript:: heirarchy on CPAN if you need something beyond monospaced text output. Trey