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

I would like to print a large text directly to the printer without having to save it in a file. I thought of using something like:  system "$$string | lp -" , but I cannot make it work. I found a lot of information on printing in Windows, or through network printers, but what I want is just to print a text using the local printer. Does anyone have an idea how to do it? Thank you.

Replies are listed 'Best First'.
Re: printing a string
by cdarke (Prior) on Apr 13, 2007 at 09:09 UTC
    Grandfather's suggestions seem reasonable, but maybe you want to do it yourself.
    The reason that your system command did not work is that nothing is actually writing to the pipe. You maybe meant:
    system "echo $$string | lp -"
    Did you mean $$string? That makes $string a reference; just thought I'd ask.
    Since the string could be large it might be better opening a pipe using
    open(my $handle,'|-', 'lp -') or die "Oops: $!";
    Then use print to write to the pipe (don't forget to close the handle).
      Thanx for all suggestions! I used used open to open a pipe and it is working! Because I am writing a gui program I would not like to have them installing modules etc.
Re: printing a string
by GrandFather (Saint) on Apr 13, 2007 at 08:00 UTC
Re: printing a string
by klekker (Pilgrim) on Apr 13, 2007 at 09:03 UTC
    Does
    # untestet! system("echo '$string' | lpr");
    work? I use a similar construct to pipe some data to gnuplot and I think an 'echo' is necessary. (And perhaps you'll have to specify the Printer with '-P PRINTERNAME', too.)

    k