Next Tricks of the Wizards 76

The Mother of All Bizarre tie Tricks

        do_something(...);
        { 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;
        }


Next Copyright © 2003 M. J. Dominus