Home > Archive > PERL Miscellaneous > July 2004 > How to print to more than one output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to print to more than one output
|
|
|
| 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
| |
| 510046470588-0001@t-online.de 2004-07-28, 9:00 pm |
| bfay@deepcosmos.ca (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
| |
| Jim Gibson 2004-07-28, 9:00 pm |
| In article <836bef72.0407260939.1bcb86e3@posting.google.com>, Bern
<bfay@deepcosmos.ca> 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.
| |
| Anno Siegel 2004-07-28, 9:00 pm |
| Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in comp.lang.perl.misc:
> In article <836bef72.0407260939.1bcb86e3@posting.google.com>, Bern
> <bfay@deepcosmos.ca> wrote:
>
>
> Not in a single print statement, no. There isn't the Perl equivalent of
> the Unix tee command.
>
>
> 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
| |
| Brian McCauley 2004-07-28, 9:01 pm |
| bfay@deepcosmos.ca (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\\
|
|
|
|
|