Next | Tricks of the Wizards | 76 |
Best application: Tied filehandle.
do_something(...);
And then to your dismay, do_domething prints a lot of blather on the STDOUT
And you cannot get it to shut up
Moreover, you want the program to examine the error log for diagnostics
So tie STDOUT:
{ my $output; tie *STDOUT => 'TrapOutput', \$output; do_something(); # Blessed silence untie *STDOUT; # Now examine $output }
sub TrapOutput::TIEHANDLE { my ($class, $var) = @_; bless $var, $class; }
sub TrapOutput::PRINT { my ($self, $string) = @_; $$self .= $string; }
Final remark: ArrayHashMonster may amaze and delight you
Next | Copyright © 2003 M. J. Dominus |