in reply to Re: IO::Tee and write / format
in thread IO::Tee and write / format

> perl -MIO::Tee -e 'my $tee = IO::Tee->new(\*STDOUT,\*STDERR); print +$tee "Test\n";' Test Test > perl -MIO::Tee -e 'my $tee = IO::Tee->new(\*STDOUT,\*STDERR,\*STDOUT +,\*STDERR); printf $tee "Test\n";' Test Test Test Test
seems to work, right ? Is something wrong with how I've used write() ?

Replies are listed 'Best First'.
Re^3: IO::Tee and write / format
by sflitman (Hermit) on Oct 17, 2008 at 06:01 UTC
    I thought the problem was the writing to a file handle bound to a string ref (\*BODY), so I tried it with IO::String, but it still didn't work:
    #!/usr/bin/perl use strict; use IO::Tee; use IO::String; my $email_body; my $tee = IO::Tee->new(\*STDOUT,new IO::String($email_body)); # crea +te a new tee object and attach STDOUT and the email$ die $! unless $tee; $tee->autoflush(1); my ( $check_description,$check_result,$severity_w ); my $VERSION = 10.0; my $host = "test"; format HEADER = ____v@<<<< @<<<<<<<<<<<_______________________________________________ +______________________________________________ $VERSION, $host Description + Check Result - Status-Severity ______________________________________________________________________ +______________________________________________ . format FAIL = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>> +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -ERROR-@> $check_description,$check_result,$severity_w . format STD = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>> +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $check_description,$check_result . select STDOUT; $^ = 'HEADER'; # set the top of page format $~ = 'STD'; $check_description = "desc"; $check_result = "result"; $severity_w = "9"; write; print "EMAIL BODY:\n\n$email_body\n"; exit;
    Had to learn something about formats, I think everything is correct except IO::Tee doesn't handle a string filehandle properly. The formats output fine if selecting STDOUT. SSF