in reply to Re: monitor STDOUT in scalar
in thread monitor STDOUT in scalar

That is very cool! It also answers a question I asked some time ago, about Line Numbers. You could use this to put line numbers in your debug log:
package MyDEBUGLOG; use Tie::Handle; @ISA = qw/Tie::Handle/; sub TIEHANDLE { my $class = shift; bless {}, $class; } { my $line = 0; sub PRINT { my $self = shift; ++$line; print DEBUGLOG map "$line: $_", @_; } } package main; tie *DEBUGLOG, 'MyDEBUGLOG'; print DEBUGLOG "Foo";
Or so I would suspect. Very cool.

Replies are listed 'Best First'.
RE: RE: Re: monitor STDOUT in scalar
by btrott (Parson) on Aug 11, 2000 at 03:08 UTC
    Well, not quite, because DEBUGLOG isn't opened for writing, for one thing, and for another, it's tied in a different package than when you're actually writing to it (main vs. MyDEBUGLOG).

    And even if you do work out those issues, I think you'll have a problem with "Deep Recursion". You're writing to a tied filehandle, which invokes the PRINT method on your tied object, which... writes to the same tied filehandle. Hence recursion.

    Check out my new Snippet, Filehandle Filter. With that you could do this:

    use Filter::Handle; local *DEBUG open DEBUG, ">debuglog" or die $!; my $f = Filter::Handle->new(\*DEBUG); print DEBUG "Foo"; print DEBUG "Bar";
      Cool, Thanks...