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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Trying to Print a File
by radiantmatrix (Parson) on Nov 05, 2004 at 19:53 UTC

    Is this "so simple" in other cross-platform interpreted languages? It's a challenge because every platform handles printing in a remarkably different manner.

    Sometimes it is simple in Perl, like on Unix:

    #Send raw data to printer on Parallel Port 0: open PRINTER, '>>', '/dev/lp0'; print PRINTER $data; close PRINTER; #Send data to lpd for printing open PRINTER, "|lpr -P $printer"; print PRINTER $data; close PRINTER;

    It's more difficult on Win32 and some other systems, because there are not convenient device files and scriptable print programs to work with. This isn't a shortcoming of Perl, it's a shortcoming of an OS that requires a plethora of system-library hooks just to print.


    <<UPDATE:
    Corion points out that Win32 systems can use the 'LPTn:' "special files", which work much like /dev/lpN files in *NIX. And, it appears that W2K finally has a scriptable print-spool command as well.

    So, I stand corrected: Perl can easily print on many an OS with ease, so the main question shows more a lack of understanding of the underlying OS than an issue with Perl.
    UPDATE ;


    As an aside, you're fortunate I'm in a good mood today, otherwise I doubt you'd get an answer -- your comment is inflamatory, and you've asked for replies to your e-mail address. The former is just rude when you're asking for help, and the latter is both rude and unadvisable unless you want your Hotmail account filled with more Spam than usual. It's not like Google and other search engines don't index the Monestary, you know...

    radiantmatrix
    require General::Disclaimer;
    "Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy

      The Win32 part is not exactly true:

      open LPR, ">LPT1:" or die "Couldn't open printer"; print LWP <>;

      Will print out a text file on the printer, much like the lpr command. Of course, there are no fancy postscript interpreters behind that... But printing any non-trivial file under Windows 2000 or higher can be done with the following, provided that there is the appropriate registry entry for the file type:

      my $file = 'foo.xls'; system("print $file");
Re: Trying to Print a File
by talexb (Chancellor) on Nov 05, 2004 at 20:26 UTC
      Why is it that nobody, but nobody, can show the actual written perl code to take a file on a hard drive and print it to a network printer or even a local printer.

    Because that's something that's usually handled quite nicely by the operating system -- thus no programming or scripting language (including Perl) needs to worry about it.

    In DOS: print THISFILE

    In Unix/Linux: lpr this.file

      I have read discussion after discussion after discussion but nobody has shown the actual statements of code that will do this.

    Your references?

      This is so simple in other languages and so basic to any programming it is unbelievable that perl can not simply say "print this file to this printer" without having to jump thru flaming hoops and installing a bunch of add-ins.

    What add-ins?

      Can anyone demonstrate this, not discuss it, but show the lines of code? please reply: (redacted)

    You've received answers to your post, but we don't do E-Mail responses. If you had provided us with a bit more background as to what you're trying to do, where you've looked already, and what you'd tried, we would be able to help you better.

    Good luck.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Trying to Print a File
by Joost (Canon) on Nov 05, 2004 at 20:08 UTC