develooper Front page | perl.beginners | Postings from August 2009

Re: removing a 'tee'd file handles going forward

Thread Previous | Thread Next
From:
Jenda Krynicky
Date:
August 26, 2009 08:44
Subject:
Re: removing a 'tee'd file handles going forward
Message ID:
4A95746F.32213.5448CFE@Jenda.Krynicky.cz
Date sent:	Wed, 26 Aug 2009 15:36:26 +0000 (GMT)
From:	Tony Esposito <tony1234567893@yahoo.co.uk>
Subject:	removing a 'tee'd file handles going forward
To:	Beginners Perl <beginners@perl.org>

> I want to output to both STDOUT and STDERR at one point in my program, then want to separate the two handles going forward in the program so that output is sent to STDOUT and STDERR separately.  Given the code snip below, would the "undef tee" do the trick?
>  
> use IO::Tee;
>
> my $tee = new IO::Tee(\*STDOUT,\*STDERR);
> $tee->print("Hi\n"); 
> $tee->flush;
>
> # some code here ... blah, blah, blah ...
> # now want to change to set and 'untee' STDOUT and STDERR ...
>
> undef tee;   # is this going to do it?

Well it will, but there is no need to do that. You can print to
STDOUT and STDERR even while the tee exists.

print $tee "Foo\n";

will go to both

print STDOUT "Foo\n";

will go to STDOUT and

print STDERR "Foo\n";

to STDERR.

And

print "Foo\n";

to the select()ed filehandle.

Jenda


===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About