in reply to Filehandle Filter
I like this, a lot. It could be a CPAN module if someone (push me and I'll do it) provided a mechanism where you could specify the output. Here's how I got around the tie-untie reference problem:
This avoids the deep recursion by not printing to a tied filehandle -- it's copied by dereference before printing to it.package Filter::Handle::Tie; use vars qw/@ISA/; use Tie::Handle; @ISA = qw/Tie::Handle/; sub TIEHANDLE { my $class = shift; my $fh = shift; bless { fh => $fh }, $class; } sub PRINT { my $self = shift; my $fh = *{ $self->{fh} }; my($file, $line) = (caller)[1,2]; print $fh sprintf "%s:%d - %s\n", $file, $line, join ' ', @_; }
Maybe users could pass in a subref with stuff they want to print instead. Interesting idea.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE (2): Filehandle Filter
by tilly (Archbishop) on Aug 11, 2000 at 05:23 UTC | |
by chip (Curate) on Aug 11, 2000 at 05:38 UTC | |
by tilly (Archbishop) on Aug 11, 2000 at 05:54 UTC | |
by tye (Sage) on Aug 11, 2000 at 17:04 UTC | |
by tilly (Archbishop) on Aug 11, 2000 at 17:27 UTC | |
by tye (Sage) on Aug 11, 2000 at 17:32 UTC | |
RE: RE: Filehandle Filter
by btrott (Parson) on Aug 11, 2000 at 05:06 UTC | |
by chromatic (Archbishop) on Aug 11, 2000 at 06:45 UTC |
In Section
Cool Uses for Perl