in reply to Saving Standard Output (overloading print())

Yes, there is a way to do it. It's called tie. If you tie a variable to a class and define the subroutines TIEHANDLE and PRINT, you can print to that variable as if it was a regular filehandle. Then, within the PRINT function, you can do whatever you want. You would do something like:
package MyPrint; use FileHandle; sub TIEHANDLE { # I'll leave this as an exercise for you. } sub PRINT { my $self = shift; my $handle = $self->{FILEHANDLE}; print $handle @_; print @_; }
Pretty simple, huh? :) If you have further questions after trying it out, post them and I'll give you some further code that I use that works.

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: Saving Standard Output (overloading print())
by Anonymous Monk on Aug 10, 2001 at 01:38 UTC
    Ah! This is what I was looking for! Wow, I never had so many fast, knowledgable responses in a forum before! I only posted a couple of hours ago...This site rocks! Anyway, thanks to all the monks that responded, I'm gunna go learn how to tie() my handles now...;) -Liam@CosmicDebris.com