After some experimenting -- no, this doesn't work. "Freezing" the write function before the tie() won't help, since the dispatch is happening later, at call time, depending of the then current ties, as can be seen in

#!/usr/bin/perl # # tying knots: how to override a tied filehandle and still access its +guts? use IO::Handle; use Data::Dumper; package Hahandle; use base qw(Tie::Handle); sub TIEHANDLE { my ($class, $ll) = @_; # ll: the "lower level ref" return bless { _ll => $ll, _llwrite => $ll->can('syswrite') }, $class; } sub WRITE { my($self, $buf, $len, $offs) = @_; $buf =~ s/(\w+)/$1 $1/g; # quite dirty syswrite(STDOUT, $buf, length($buf), $offs); } sub llwrite { my $self = shift; $self->{_llwrite}($self->{_ll}, @_); } ################ package main; my $out = IO::Handle->new_from_fd(STDOUT, "w"); $out->write("(0) bong!\n"); my $wr = $out->can('syswrite'); tie(*$out, 'Hahandle', $out); $out->write("(1) bong!\n"); &$wr($out, "(2) bong!\n");

which yields

(0) bong! (1 1) bong bong! (2 2) bong bong!

Gaah. Of course, I might do fdopen before tie()ing, but I guess I'd lose the original tie. Help. Is there a way to "stack ties"?


In reply to Re: IO::Multiplex and tied handles? by oldtomas
in thread IO::Multiplex and tied handles? by oldtomas

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.