How to print to more than one output

Discussion in 'Perl Misc' started by Bern, Jul 26, 2004.

  1. Bern

    Bern Guest

    Hello list,

    Is it possible to print to two different output at once?

    For example, I tried the following but it does not work. Nothing shows
    up in the log file.

    open(LOG, ">test.log") or die "Can't create log file: $!";
    print { LOG && STDOUT } `ls -l`;

    Thanks,
    Bern
    Bern, Jul 26, 2004
    #1
    1. Advertising

  2. Bern

    Guest

    (Bern) writes:


    > Is it possible to print to two different output at once?



    one may exec the tee command and pipe into it.


    Klaus Schilling
    , Jul 26, 2004
    #2
    1. Advertising

  3. Bern

    Anno Siegel Guest

    Jim Gibson <> wrote in comp.lang.perl.misc:
    > In article <>, Bern
    > <> wrote:
    >
    > > Hello list,
    > >
    > > Is it possible to print to two different output at once?

    >
    > Not in a single print statement, no. There isn't the Perl equivalent of
    > the Unix tee command.
    >
    > >
    > > For example, I tried the following but it does not work. Nothing shows
    > > up in the log file.
    > >
    > > open(LOG, ">test.log") or die "Can't create log file: $!";
    > > print { LOG && STDOUT } `ls -l`;

    >
    > This will print to STDOUT only, because the block returns the value of
    > the STDOUT file handle, following the rules of the logical and
    > operator. The LOG file handle is evaluated first, and, because it is
    > true, the STDOUT is evaluated next and returned as the value of the
    > expression.
    >
    > You will have to write your own subroutine to output to two or file
    > handles.


    The IO::Tee module on CPAN also handles this.

    Anno
    Anno Siegel, Jul 26, 2004
    #3
  4. (Bern) writes:

    > Subject: Re: How to print to more than one output
    >
    > Is it possible to print to two different output at once?


    This is FAQ: How do I print to more than one file at once?

    Please consult the FAQ _before_ posting a question.

    Note the there are two answers to this (the ones you've been given
    already) and oddly older versions of the FAQ give one and newer
    versions the other.

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley, Jul 27, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    897
  2. Merciadri Luca
    Replies:
    4
    Views:
    798
  3. PerlFAQ Server
    Replies:
    0
    Views:
    90
    PerlFAQ Server
    Jan 7, 2011
  4. Steven D'Aprano
    Replies:
    0
    Views:
    75
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    68
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page