This question arose from a previous one related to filtering the output of Parse::RecDescent:

http://www.perlmonks.com/index.pl?node_id=209943

I 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.


In reply to Tie'ing writes to formats by ruscoekm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.