1IO::Tee(3) User Contributed Perl Documentation IO::Tee(3)
2
3
4
6 IO::Tee - Multiplex output to multiple output handles
7
9 use IO::Tee;
10
11 $tee = IO::Tee->new($handle1, $handle2);
12 print $tee "foo", "bar";
13 my $input = <$tee>;
14
16 "IO::Tee" objects can be used to multiplex input and output in two
17 different ways. The first way is to multiplex output to zero or more
18 output handles. The "IO::Tee" constructor, given a list of output
19 handles, returns a tied handle that can be written to. When written to
20 (using print or printf), the "IO::Tee" object multiplexes the output to
21 the list of handles originally passed to the constructor. As a
22 shortcut, you can also directly pass a string or an array reference to
23 the constructor, in which case "IO::File::new" is called for you with
24 the specified argument or arguments.
25
26 The second way is to multiplex input from one input handle to zero or
27 more output handles as it is being read. The "IO::Tee" constructor,
28 given an input handle followed by a list of output handles, returns a
29 tied handle that can be read from as well as written to. When written
30 to, the "IO::Tee" object multiplexes the output to all handles passed
31 to the constructor, as described in the previous paragraph. When read
32 from, the "IO::Tee" object reads from the input handle given as the
33 first argument to the "IO::Tee" constructor, then writes any data read
34 to the output handles given as the remaining arguments to the
35 constructor.
36
37 The "IO::Tee" class supports certain "IO::Handle" and "IO::File"
38 methods related to input and output. In particular, the following
39 methods will iterate themselves over all handles associated with the
40 "IO::Tee" object, and return TRUE indicating success if and only if all
41 associated handles returned TRUE indicating success:
42
43 close
44 truncate
45 write
46 syswrite
47 format_write
48 formline
49 fcntl
50 ioctl
51 flush
52 clearerr
53 seek
54
55 The following methods perform input multiplexing as described above:
56
57 read
58 sysread
59 readline
60 getc
61 gets
62 eof
63 getline
64 getlines
65
66 The following methods can be used to set (but not retrieve) the current
67 values of output-related state variables on all associated handles:
68
69 autoflush
70 output_field_separator
71 output_record_separator
72 format_page_number
73 format_lines_per_page
74 format_lines_left
75 format_name
76 format_top_name
77 format_line_break_characters
78 format_formfeed
79
80 The following methods are directly passed on to the input handle given
81 as the first argument to the "IO::Tee" constructor:
82
83 input_record_separator
84 input_line_number
85
86 Note that the return value of input multiplexing methods (such as
87 "print") is always the return value of the input action, not the return
88 value of subsequent output actions. In particular, no error is
89 indicated by the return value if the input action itself succeeds but
90 subsequent output multiplexing fails.
91
93 use IO::Tee;
94 use IO::File;
95
96 my $tee = new IO::Tee(\*STDOUT,
97 new IO::File(">tt1.out"), ">tt2.out");
98
99 print join(' ', $tee->handles), "\n";
100
101 for (1..10) { print $tee $_, "\n" }
102 for (1..10) { $tee->print($_, "\n") }
103 $tee->flush;
104
105 $tee = new IO::Tee('</etc/passwd', \*STDOUT);
106 my @lines = <$tee>;
107 print scalar(@lines);
108
110 <https://github.com/neilb/IO-Tee>
111
113 Chung-chieh Shan, ken@digitas.harvard.edu
114
115 As of August 2017, now being maintained by Neil Bowers.
116
118 Copyright (c) 1998-2017 Chung-chieh Shan. All rights reserved. This
119 program is free software; you can redistribute it and/or modify it
120 under the same terms as Perl itself.
121
123 perlfunc, IO::Handle, IO::File.
124
125
126
127perl v5.36.0 2022-07-22 IO::Tee(3)