in reply to IO::Tee and write / format

I don't think you can use an IO::Tee object as a filehandle, but you can invoke most IO::Handle and IO::File methods with it. Take a closer look at IO:Tee, and look at IO::Handle.

Replies are listed 'Best First'.
Re^2: IO::Tee and write / format
by ikegami (Patriarch) on Oct 17, 2008 at 04:03 UTC

    I don't think you can use an IO::Tee object as a filehandle

    IO::Tee objects are (tied) file handles.

Re^2: IO::Tee and write / format
by Anonymous Monk on Oct 17, 2008 at 05:13 UTC
    > 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() ?
      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