string - Perl: Print on the "display" and also into a file -
is there way print both onto "display" , file @ same time without repeating print "string" code?
what want do:
if ($ofile) { open (file, '>>', "file"); print "hello" #some code#; #prints on display , file }
instead of:
if ($ofile) { open (file, '>>', "file"); } print "hello"; if ($ofile) { print file "hello"; }
tried googling found either or, not both features together.
edit add questions:
then use io::tee create new tee'd handle, , select $tee print uses default. – eric strom
@ericstrom mean create new tee'd handle? mean local::teeoutput
? search.cpan.org/~mschilli/log-log4perl-1.34/lib/log/log4perl.pm
@ericstrom have example?
@ericstrom local::teeoutput not available in default library strawberry perl. there alternative that's inside default library?
sure, io::tee on cpan.
my $tee = io::tee->new( \*stdout, \*stderr, $john, $tan ); print $tee "hello!\n";
to change perl's default handle:
select $tee; print "hello!\n";
Comments
Post a Comment