in reply to IO::Tee and write / format
The following code snippet should get you started. Notice that since the name of the format is passed down to IO::Tee, you need to specify the full package name of the format (o/wise you get complaints about undefined formats from IO::Tee).
use strict; use warnings; use IO::Tee; my( $abc, $xyz ) = ( q/hello/, 12345 ); format TEE_TOP = ==== Top of Output ==== . format TEE = @<<<<< @##### $abc, $xyz . # with lexical file handle; can also use bareword handle open my $outfile, '>', 'junk.out' or die "error opening junk.out: ($! +)"; my $tee = IO::Tee->new( \*STDOUT, $outfile ); # see docs for IO::Tee and IO::Handle for explanation of these methods # and others available for proper format use/control $tee->format_top_name( q/main::TEE_TOP/ ); $tee->format_write( q/main::TEE/ );
-> ./tst-tee-write ==== Top of Output ==== hello 12345 -> cat junk.out ==== Top of Output ==== hello 12345
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: IO::Tee and write / format
by beadon (Initiate) on Oct 17, 2008 at 17:28 UTC | |
by broomduster (Priest) on Oct 17, 2008 at 19:36 UTC |