ruscoekm has asked for the wisdom of the Perl Monks concerning the following question:
This question arose from a previous one related to filtering the output of Parse::RecDescent:
http://www.perlmonks.com/index.pl?node_id=209943I thought I would reproduce it in a new thread, as the old one is now rather buried in the chain.
In the example code below, the prints come through fine but the writes do not. It seems as though writes to a format cannot be tied:
use strict; use warnings; package Log::OPG::Info; use Tie::Handle; use base qw(Tie::StdHandle); sub WRITE { print "Good\n"; } package main; format STDERR = Bad . tie *STDERR, 'Log::OPG::Info'; print STDERR ''; write STDERR;
Whereas I hope for the output:
Good Good
I actually get:
Good Bad
So, either I am missing something obvious, or the question is:
"How does one tie writes to a format?"
Cheers Kevin
P.S. I faintly remember that it is possible to name individual slots in hash table entries, along the lines of $::slot{SCALAR} and $::slot{FORMAT}. Perhaps that might form the basis for a solution, but the details escape me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Tie'ing writes to formats
by merlyn (Sage) on Nov 02, 2002 at 15:08 UTC | |
by ruscoekm (Monk) on Nov 02, 2002 at 15:29 UTC | |
|
Re: Tie'ing writes to formats
by runrig (Abbot) on Nov 02, 2002 at 17:53 UTC | |
by ruscoekm (Monk) on Nov 02, 2002 at 18:03 UTC | |
|
Re: Tie'ing writes to formats
by broquaint (Abbot) on Nov 02, 2002 at 18:18 UTC | |
by ruscoekm (Monk) on Nov 02, 2002 at 19:02 UTC |